#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if ((n == 1 && m != 2) || (m == 1 && n != 2) || (m & 1 && n & 1))
    printf("1\n%d %d 1 1\n", n, m);
  else
    puts("0");
  if (n == 1) {
    for (int i = 1; i <= m; i++) printf("1 %d\n", i);
    puts("1 1");
  } else if (m == 1) {
    for (int i = 1; i <= n; i++) printf("%d 1\n", i);
    puts("1 1");
  } else if (m & 1 && n & 1) {
    for (int i = 1; i <= n; i++)
      if (i & 1)
        for (int j = 1; j <= m; j++) printf("%d %d\n", i, j);
      else
        for (int j = m; j >= 1; j--) printf("%d %d\n", i, j);
    puts("1 1");
  } else if (n & 1) {
    puts("1 1");
    for (int i = 1; i <= m; i++)
      if (i & 1)
        for (int j = 2; j <= n; j++) printf("%d %d\n", j, i);
      else
        for (int j = n; j >= 2; j--) printf("%d %d\n", j, i);
    for (int i = m; i >= 1; i--) printf("1 %d\n", i);
  } else {
    puts("1 1");
    for (int i = 1; i <= n; i++)
      if (i & 1)
        for (int j = 2; j <= m; j++) printf("%d %d\n", i, j);
      else
        for (int j = m; j >= 2; j--) printf("%d %d\n", i, j);
    for (int i = n; i >= 1; i--) printf("%d 1\n", i);
  }
  return 0;
}
