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