import Foundation //getting the number of birds let n = Int(readLine()!)! //getting the types of birds let arrTypes = readLine()!.components(separatedBy: " ").map{ Int($0)! } //creating set for duplicated types let countedSet = NSCountedSet() countedSet.addObjects(from: arrTypes) var duplicatedDict = [String:Int]() //iterating through bird types for (index, item) in arrTypes.enumerated() { let key = "\(item)" if duplicatedDict[key] == nil { duplicatedDict[key] = countedSet.count(for: item) } } let maxTypes = duplicatedDict.values.max() let resultTypes = duplicatedDict.filter { $1 == maxTypes }.map { $0.0 } print(resultTypes.min()!)