#include using namespace std; int main() { int n, i, j, a[100000], b, c; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = n; i >= 2; i--) { for (j = 1; j <= n; j++) { if (a[j] == i - 1) b = j; if (a[j] == i) c = j; } if (b > c) { cout << i - 1 << endl; return 0; } } cout << 0 << endl; }