#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if ((n % 2 && m % 2) || (n == 1 && m != 2) || (m == 1 && n != 2)) {
    printf("1\n");
    printf("%d %d 1 1\n", n, m);
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      if (!flag) {
        for (int j = 1; j <= m; j++) {
          printf("%d %d\n", i, j);
        }
        flag = !flag;
      } else {
        for (int j = m; j >= 1; j--) {
          printf("%d %d\n", i, j);
        }
        flag = !flag;
      }
    }
    printf("1 1\n");
    return 0;
  }
  printf("0\n");
  if (n % 2 == 0) {
    for (int j = 1; j <= m; j++) printf("1 %d\n", j);
    bool flag = true;
    for (int i = 2; i <= n; i++) {
      if (!flag) {
        for (int j = 2; j <= m; j++) {
          printf("%d %d\n", i, j);
        }
        flag = !flag;
      } else {
        for (int j = m; j >= 2; j--) {
          printf("%d %d\n", i, j);
        }
        flag = !flag;
      }
    }
    for (int i = n; i >= 1; i--) printf("%d 1\n", i);
    return 0;
  }
  for (int j = 1; j <= n; j++) printf("%d 1\n", j);
  bool flag = true;
  for (int i = 2; i <= m; i++) {
    if (!flag) {
      for (int j = 2; j <= n; j++) {
        printf("%d %d\n", j, i);
      }
      flag = !flag;
    } else {
      for (int j = n; j >= 2; j--) {
        printf("%d %d\n", j, i);
      }
      flag = !flag;
    }
  }
  for (int i = m; i >= 1; i--) printf("1 %d\n", i);
  return 0;
}
