#include using namespace std; typedef pair P; int main() { int N, M; cin >> N >> M; int v_max = -1; int ans = -1; for (int i=0; i> E[i]; E[i]--; idx[E[i]] = i; } int v = 0; for (int j=0; j vec; vec.push_back(P(j, idx[j])); vec.push_back(P(k, idx[k])); vec.push_back(P(l, idx[l])); sort(vec.begin(), vec.end(), [](auto const& lhs, auto const& rhs) {return lhs.secondvec[2].first) || (vec[0].firstvec[2].first)) { prof = max(prof, max({j, k, l})); } } v += prof; } } if (v>v_max) { v_max = v; ans = i; } } cout << ans << endl; }