#include <bits/stdc++.h>   using namespace std;   int mas[1010][1010];   int main() {     int N, K;     cin >> N >> K;     for (int i = 1; i <= N; i++) {       int k = 0;       for (int j = 1; j <= N; j++) {         if (k == K)           break;         else if (i == j)           continue;         else if (mas[j][i] || mas[i][j])           continue;         else {           mas[i][j] = 1;           k++;         }       }       if (k < K) {         cout << -1 << endl;         return 0;       }     }     int cnt = 0;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) {         if (mas[i][j]) cnt++;       }     }     cout << cnt << endl;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) {         if (mas[i][j]) cout << i <<     << j << endl;       }     }     return 0;   }   