#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if ((n * m) & 1 || (n == 1 && m != 2) || (m == 1 && n != 2)) {
    cout << 1 << endl
         << n << " " << m << " "
         << "1 1\n";
    for (int i = 1, f = 1; i <= n; f ^= 1, ++i)
      if (f)
        for (int j = 1; j <= m; ++j) cout << i << " " << j << endl;
      else
        for (int j = m; j > 0; --j) cout << i << " " << j << endl;
    cout << "1 1\n";
  } else {
    cout << "0\n1 1\n";
    if (m & 1) {
      for (int i = 1, f = 1; i <= n; f ^= 1, ++i)
        if (f)
          for (int j = 2; j <= m; ++j) cout << i << " " << j << endl;
        else
          for (int j = m; j > 1; --j) cout << i << " " << j << endl;
      for (int j = n; j > 0; --j) cout << j << " 1" << endl;
    } else {
      for (int i = 1, f = 1; i <= m; f ^= 1, ++i)
        if (f)
          for (int j = 2; j <= n; ++j) cout << j << " " << i << endl;
        else
          for (int j = n; j > 1; --j) cout << j << " " << i << endl;
      for (int j = m; j > 0; --j) cout << "1 " << j << endl;
    }
  }
}
