#include using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,m,cnt = 0; cin >> n >> m; vector a(n); for(int i=0;i> a[i]; for(int i=0;i a[j]){ swap(a[i], a[j]); cnt ++; } } } for(int i=0;i a[i+1]) cnt = -1; cout << cnt; }