#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin >> N >> Q; map> rev; for(int i=0; i> a; rev[a].push_back(i); } int inf = 1e9; vector dp(N,inf); dp.at(0) = 0; while(Q--){ int b; cin >> b; vector &ap = rev[b],next(N,inf); int pos = 0; for(int i=0; i=0; i--) next.at(i) = min(next.at(i),next.at(i+1)+1); swap(dp,next); } cout << *min_element(dp.begin(),dp.end()) << endl; }