process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function main() { const n = parseInt(readLine()); types = readLine().split(' '); types = types.map(Number); let max_count = 0; let max_type; const occur = {}; types.forEach( el => { occur[el] !== undefined ? occur[el] +=1 : occur[el] = 1 if (occur[el] == max_count) { if (el < max_type) max_type = el; } if (occur[el] > max_count) { max_count = occur[el]; max_type = el; } }) console.log(max_type); }