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