#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
template <typename T>
T getnum() {
  int sign = 1;
  T ret = 0;
  char c;
  do {
    c = getchar();
  } while (c == ' ' || c == '\n');
  if (c == '-')
    sign = -1;
  else
    ret = c - '0';
  while (1) {
    c = getchar();
    if (c < '0' || c > '9') break;
    ret = 10 * ret + c - '0';
  }
  return sign * ret;
}
inline void ini(int& x) { x = getnum<int>(); }
inline void scani(int& x) { scanf("%d", &x); }
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (n * m > 2 && (n == 1 || m == 1)) {
    cout << 1 << endl;
    cout << n << " " << m << " 1 1" << endl;
    if (n == 1) {
      for (int j = 1; j <= m; j += 1) cout << 1 << " " << j << endl;
    } else {
      for (int i = 1; i <= n; i += 1) cout << i << " " << 1 << endl;
    }
    cout << "1 1" << endl;
  } else if ((n * m) & 1) {
    cout << 1 << endl;
    cout << n << " " << m << " 1 1" << endl;
    for (int i = 1; i <= n; i += 1) {
      if (i & 1) {
        for (int j = 1; j <= m; j += 1) {
          cout << i << " " << j << endl;
        }
      } else {
        for (int j = m; j >= 1; j -= 1) {
          cout << i << " " << j << endl;
        }
      }
    }
    cout << "1 1" << endl;
  } else {
    cout << 0 << endl;
    cout << "1 1" << endl;
    if (m & 1) {
      for (int i = 1; i <= n; i += 1) {
        if (i & 1) {
          for (int j = 2; j <= m; j += 1) cout << i << " " << j << endl;
        } else {
          for (int j = m; j >= 2; j -= 1) cout << i << " " << j << endl;
        }
      }
      for (int i = n; i >= 1; i -= 1) cout << i << " " << 1 << endl;
    } else {
      for (int j = 1; j <= m; j += 1) {
        if (j & 1) {
          for (int i = 2; i <= n; i += 1) cout << i << " " << j << endl;
        } else {
          for (int i = n; i >= 2; i -= 1) cout << i << " " << j << endl;
        }
      }
      for (int j = m; j >= 1; j -= 1) cout << 1 << " " << j << endl;
    }
  }
  return 0;
}
