#include <bits/stdc++.h>
using namespace std;
int main() {
  int sum = 0;
  int a, b;
  cin >> a >> b;
  int c = a * a;
  int k[a][a];
  if (b == 1) {
    int n = 1;
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < a; j++) {
        if (j == 0) sum += n;
        k[i][j] = n;
        n++;
      }
    }
    cout << sum << endl;
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < a; j++) {
        cout << k[i][j] << " ";
      }
      cout << endl;
    }
  } else {
    for (int i = 0; i < a; i++) {
      for (int j = a - 1; j >= b - 1; j--) {
        if (j == b - 1) sum += c;
        k[i][j] = c--;
      }
    }
    int n = 1;
    for (int i = a - 1; i >= 0; i--) {
      for (int j = 0; j < b - 1; j++) {
        k[i][j] = n;
        n++;
      }
    }
    cout << sum << endl;
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < a; j++) {
        cout << k[i][j] << " ";
      }
      cout << endl;
    }
  }
}
