#include <bits/stdc++.h>
using namespace std;
int x[11000], y[11000];
bool bo[110][110];
int mx[] = {0, 1, 0, -1}, my[] = {1, 0, -1, 0};
int main() {
  int i, j, k, l, n, m, t, c, xx, yy;
  while (scanf("%d%d", &n, &m) == 2) {
    c = t = 0;
    memset(bo, false, sizeof(bo));
    if (n == 1) {
      if (m == 2)
        printf("0\n");
      else {
        printf("1\n");
        printf("1 %d 1 1\n", m);
      }
      for (i = 1; i < m + 1; i++) printf("1 %d\n", i);
      printf("1 1\n");
    } else if (m == 1) {
      if (n == 2)
        printf("0\n");
      else {
        printf("1\n");
        printf("%d 1 1 1\n", n);
      }
      for (i = 1; i < n + 1; i++) printf("%d 1\n", i);
      printf("1 1\n");
    } else if (m % 2 == 0) {
      for (i = 1; i < n; i++) {
        x[c] = 1;
        y[c] = i;
        c++;
      }
      for (i = 1; i < m; i++) {
        x[c] = i;
        y[c] = n;
        c++;
      }
      for (i = n; i > 0; i--) {
        x[c] = m;
        y[c] = i;
        c++;
      }
      xx = m;
      yy = 0;
      while (xx > 3) {
        --xx;
        for (i = 1; i < n; i++) {
          x[c] = xx;
          y[c] = ++yy;
          bo[y[c]][x[c]] = false;
          c++;
        }
        --xx;
        for (i = 1; i < n; i++) {
          x[c] = xx;
          y[c] = yy--;
          bo[y[c]][x[c]] = false;
          c++;
        }
      }
      if (y[c - 1] + x[c - 1] == 3)
        printf("0\n");
      else {
        printf("1\n");
        printf("%d %d %d %d\n", y[c - 1], x[c - 1], 1, 1);
      }
      for (i = 0; i < c; i++) printf("%d %d\n", y[i], x[i]);
      printf("%d %d\n", 1, 1);
    } else {
      for (i = 1; i < m; i++) {
        x[c] = i;
        y[c] = 1;
        c++;
      }
      for (i = 1; i < n; i++) {
        x[c] = m;
        y[c] = i;
        c++;
      }
      for (i = m; i > 0; i--) {
        x[c] = i;
        y[c] = n;
        c++;
      }
      xx = 0;
      yy = n;
      while (yy > 2) {
        --yy;
        for (i = 1; i < m; i++) {
          x[c] = ++xx;
          y[c] = yy;
          c++;
        }
        if (yy == 2) break;
        --yy;
        for (i = 1; i < m; i++) {
          x[c] = xx--;
          y[c] = yy;
          c++;
        }
      }
      if (y[c - 1] + x[c - 1] == 3)
        printf("0\n");
      else {
        printf("1\n");
        printf("%d %d %d %d\n", y[c - 1], x[c - 1], 1, 1);
      }
      for (i = 0; i < c; i++) printf("%d %d\n", y[i], x[i]);
      printf("%d %d\n", 1, 1);
    }
  }
  return 0;
}
