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