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