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