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