#include <iostream>
#include <vector>
int main() {
int n;
std::cin >> n;
std::vector<int> numbers(n);
for (int i = 0; i < n; ++i) {
std::cin >> numbers[i];
}
int closestValue = -1;
int minDifference = 1000000; // Valoare mare predefinită
for (int i = 0; i < n; ++i) {
// Calculăm diferența fără a folosi std::abs
int difference = numbers[i] - n;
if (difference < 0) {
difference = -difference; // Facem diferența pozitivă
}
// Verificăm dacă diferența este mai mică decât diferența minimă
if (difference < minDifference) {
minDifference = difference;
closestValue = numbers[i];
} else if (difference == minDifference) {
// Dacă avem o diferență egală, alegem valoarea minimă
if (numbers[i] < closestValue) {
closestValue = numbers[i];
}
}
}
std::cout << closestValue;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKaW50IG1haW4oKSB7CiAgICBpbnQgbjsKICAgIHN0ZDo6Y2luID4+IG47CgogICAgc3RkOjp2ZWN0b3I8aW50PiBudW1iZXJzKG4pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBzdGQ6OmNpbiA+PiBudW1iZXJzW2ldOwogICAgfQoKICAgIGludCBjbG9zZXN0VmFsdWUgPSAtMTsKICAgIGludCBtaW5EaWZmZXJlbmNlID0gMTAwMDAwMDsgLy8gVmFsb2FyZSBtYXJlIHByZWRlZmluaXTEgwoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgLy8gQ2FsY3VsxINtIGRpZmVyZW7Im2EgZsSDcsSDIGEgZm9sb3NpIHN0ZDo6YWJzCiAgICAgICAgaW50IGRpZmZlcmVuY2UgPSBudW1iZXJzW2ldIC0gbjsKICAgICAgICBpZiAoZGlmZmVyZW5jZSA8IDApIHsKICAgICAgICAgICAgZGlmZmVyZW5jZSA9IC1kaWZmZXJlbmNlOyAvLyBGYWNlbSBkaWZlcmVuyJthIHBveml0aXbEgwoKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgLy8gVmVyaWZpY8S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