#include <bits/stdc++.h>
using namespace std;
long long a[502][502];
int main() {
  long long i, j, n, k, x, p;
  while (scanf("%lld %lld", &n, &k) == 2) {
    long long tmp = 1;
    x = n * (k - 1);
    if (k == 1) {
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
          a[i][j] = tmp;
          tmp++;
        }
      }
    } else {
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
          if (j >= k) {
            a[i][j] = ++x;
          } else {
            a[i][j] = tmp;
            tmp++;
          }
        }
      }
    }
    long long s = 0;
    for (i = 1; i <= n; i++) {
      s += a[i][k];
    }
    cout << s << endl;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        printf("%lld", a[i][j]);
        if (j != n) printf(" ");
      }
      printf("\n");
    }
  }
  return 0;
}
