#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j;
  cin >> n >> m;
  if (n == 1 || m == 1) {
    if (n * m == 2)
      cout << 0 << endl;
    else {
      cout << 1 << endl;
      cout << n << ' ' << m << " 1 1" << endl;
    }
    for (i = 1; i <= n; ++i) {
      for (j = 1; j <= m; ++j) {
        cout << i << ' ' << j << endl;
      }
    }
    cout << "1 1" << endl;
    return 0;
  }
  if (n * m & 1) {
    cout << 1 << endl;
    cout << n << ' ' << m << " 1 1" << endl;
    for (i = 1; i <= n; ++i) {
      for (j = 1; j <= m; ++j) {
        cout << i << ' ';
        if (i & 1)
          cout << j << endl;
        else
          cout << m - j + 1 << endl;
      }
    }
    cout << "1 1" << endl;
    return 0;
  }
  cout << 0 << endl;
  cout << "1 1" << endl;
  if ((n & 1) == 0) {
    for (i = 1; i <= n; ++i) {
      for (j = 2; j <= m; ++j) {
        cout << i << ' ';
        if (i & 1)
          cout << j << endl;
        else
          cout << m - j + 2 << endl;
      }
    }
    for (i = n; i > 0; --i) cout << i << ' ' << 1 << endl;
    return 0;
  }
  for (j = 1; j <= m; ++j) {
    for (i = 2; i <= n; ++i) {
      if (j & 1)
        cout << i << ' ';
      else
        cout << n - i + 2 << ' ';
      cout << j << endl;
    }
  }
  for (j = m; j > 0; --j) cout << 1 << ' ' << j << endl;
  return 0;
}
