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