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