import java.util.*;
public class traveseKing {
public static Scanner scn = new Scanner(System.in);
public static int counter = 0;
public static boolean isTelepoter(int[][] arr, int i, int j, int n, int m, int count, ArrayList<int[]> al,
int[][] dir) {
if (n == 1 && m == 1) {
System.out.println(0 + "\n" + 1 + "\t" + 1);
return true;
}
if (count >= n * m - 1 && ((i == 1 && j == 2) || (i == 2 && j == 1))) {
System.out.println(0 + "\n" + 1 + "\t" + 1);
for (int x = 0; x < al.size(); x++) {
for (int y = 0; y < 2; y++) {
System.out.print(al.get(x)[y] + "\t");
}
System.out.println();
}
System.out.println(1 + "\t" + 1);
return true;
}
if (count >= n * m - 1)
counter = count + 1;
if (counter >= n * m)
return false;
boolean recAns = false;
for (int x = 0; x < dir.length; x++) {
int newi = 0, newj = 0;
newi = i + dir[x][0];
newj = j + dir[x][1];
if ((newi <= n && newi >= 1) && (newj <= m && newj >= 1) && arr[newi - 1][newj - 1] < 1) {
al.add(new int[] { newi, newj });
arr[newi - 1][newj - 1]++;
recAns = isTelepoter(arr, newi, newj, n, m, count + 1, al, dir);
al.remove(al.size() - 1);
arr[newi - 1][newj - 1]--;
}
if (recAns)
return true;
}
return recAns;
}
public static void traverse(int[][] arr, int i, int j, int n, int m, ArrayList<int[]> al) {
boolean istele= false;
int[][] dirOdd = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
int[][] dirEven = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };
if (m % 2 == 1 && !(n % 2 == 1 && m % 2 == 1))
istele = isTelepoter(arr, 1, 1, n, m, 0, al, dirOdd);
if(m%2==0 && !(n % 2 == 1 && m % 2 == 1))
istele = isTelepoter(arr, 1, 1, n, m, 0, al, dirEven);
if (!istele) {
System.out.println(1);
if (n % 2 == 1)
System.out.println(n + "\t" + m + "\t" + 1 + "\t" + 1);
else
System.out.println(n + "\t" + 1 + "\t" + 1 + "\t" + 1);
for (int x = 0; x < n; x++) {
if (x % 2 == 0)
for (int y = 0; y < m; y++) {
System.out.println((x + 1) + "\t" + (y + 1));
}
else
for (int y = m - 1; y >= 0; y--) {
System.out.println((x + 1) + "\t" + (y + 1));
}
}
System.out.println(1 + "\t" + 1);
}
}
public static void main(String[] argv) {
int n = scn.nextInt();
int m = scn.nextInt();
ArrayList<int[]> al = new ArrayList<>();
int[][] arr = new int[n][m];
traverse(arr, 1, 1, n, m, al);
}
}