#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  ifstream from;
  const long long nmin = 1, nmax = 100, mmin = 1, mmax = 100;
  long long n, m, res, rt, i, j, k, ax, x, y;
  if (0) from.open("test.txt");
  cin >> n >> m;
  vector<long long> vx, vy;
  res = 0;
  if ((n % 2 == 0) && ((m > 1) || (n * m == 2))) {
    vx.push_back(1);
    vy.push_back(1);
    for (i = 1; i <= n; i++) {
      for (j = 2; j <= m; j++) {
        vx.push_back(i);
        rt = j * (i % 2) + (m + 2 - j) * (1 - i % 2);
        vy.push_back(rt);
      }
    }
    for (i = n; i >= 1; i--) {
      vx.push_back(i);
      vy.push_back(1);
    }
  } else if ((m % 2 == 0) && ((n > 1) || (n * m == 2))) {
    vx.push_back(1);
    vy.push_back(1);
    for (j = 1; j <= m; j++) {
      for (i = 2; i <= n; i++) {
        vy.push_back(j);
        rt = i * (j % 2) + (n + 2 - i) * (1 - j % 2);
        vx.push_back(rt);
      }
    }
    for (j = m; j >= 1; j--) {
      vx.push_back(1);
      vy.push_back(j);
    }
  } else {
    res = 1;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        vx.push_back(i);
        rt = j * (i % 2) + (m + 1 - j) * (1 - i % 2);
        vy.push_back(rt);
      }
    }
    vx.push_back(1);
    vy.push_back(1);
  }
  cout << res << endl;
  if (res == 1) cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
  rt = vx.size();
  for (i = 0; i < rt; i++) cout << vx[i] << ' ' << vy[i] << endl;
  return 0;
}
