#include <bits/stdc++.h>
using namespace std;
long long arr[550][550];
vector<pair<long long, long long> > v;
int main() {
  ios_base::sync_with_stdio(false);
  long long i, j, k, n, m, t, cont, a, b;
  cin >> n >> m;
  m--;
  long long maxi = n * n;
  long long yo = maxi - (n - m - 1);
  long long ansi = 0;
  for (i = n - 1; i >= 0; i--) {
    arr[i][m] = yo;
    ansi += yo;
    yo -= (n - m);
  }
  for (i = 0; i < n; i++) {
    long long ha = arr[i][m];
    for (j = m + 1; j < n; j++) {
      arr[i][j] = ha + 1;
      ha++;
    }
  }
  long long ba = arr[0][m];
  long long gf = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      arr[i][j] = gf;
      gf++;
    }
  }
  cout << ansi << endl;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      cout << arr[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
  return 0;
}
