/************************************************
Grundlegende Algorithmen mit Java,
http://algorithmen-und-problemloesungen.de/
Copyright @2007-2008 by Doina Logofatu
************************************************/

import java.io.*;
import java.util.*;

public class P08Springer {

  private static final String FileOutputName = "springer.out";
  private int nSol;
  private int[][] table;
  private PrintStream out;
  private int n;

  public P08Springer(int n, PrintStream out) {
    this.n = n;
    this.table = new int[n][n];
    this.out = out;

  }

  private void writeSolution() {
    out.print(" Loesung: ");
    out.println(++nSol);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        out.printf("%3d ", table[i][j]);
      out.println();
    }
  }

  void run(int l, int c) {
    this.nSol = 0;
    this.table[l - 1][c - 1] = 1;
    this.back(l - 1, c - 1, 1);
  }

  private void back(int l, int c, int step) {
    if (n * n == step) {
      writeSolution();
      return;
    }
    int dx, dy, lnew, cnew;
    for (dx = -2; dx < 3; dx++)
      for (dy = -2; dy < 3; dy++)
        if (Math.abs(dx * dy) == 2) {
          lnew = l + dx;
          cnew = c + dy;
          if (0 <= lnew && lnew < n && 0 <= cnew && cnew < n
              && table[lnew][cnew] == 0) {
            table[lnew][cnew] = step + 1;
            back(l + dx, c + dy, step + 1);
            table[lnew][cnew] = 0;
          }
        }
  }

  public static void main(String[] args) throws IOException {
    PrintStream out = new PrintStream(new File(FileOutputName));
    try {
      Scanner sc = new Scanner(System.in);
      int l = sc.nextInt();
      int c = sc.nextInt();
      new P08Springer(5, out).run(l, c);
    } finally {
      out.close();
    }
  }
}

