#include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } void solve() { int n, k; cin >> n >> k; vector p(n); rep(i, 0, n) cin >> p[i], p[i]--; vector> v(k); rep(i, 0, n) v[i % k].push_back(p[i]); vector> ans; rep(i, 0, k) { int f = 0; for(int x : v[i]) if(x % k != i) f = 1; if(f) { cout << "-1\n"; return; } int m = v[i].size(); rep(lp, 0, m) rep(j, 0, m - 1) { if(v[i][j] > v[i][j + 1]) { swap(v[i][j], v[i][j + 1]); ans.push_back({j * k + i, j * k + i + k}); } } } cout << ans.size() << '\n'; for(auto [x, y] : ans) { cout << x + 1 << ' ' << y + 1 << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }