#include <bits/stdc++.h>
long long int mod = 1000000000 + 7;
long long int inf = (long long int)(5e18);
using namespace std;
mt19937 unlucko(chrono::steady_clock::now().time_since_epoch().count());
bool field[100][100];
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int mvs = n * m;
  vector<pair<int, int> > ans;
  if (n % 2 == 1 && m % 2 == 1 || (n == 1 || m == 1)) {
    if (n == 2) {
      cout << "0\n";
      ans.push_back({0, 0});
      ans.push_back({1, 0});
      ans.push_back({0, 0});
    } else if (m == 2) {
      cout << "0\n";
      ans.push_back({0, 0});
      ans.push_back({0, 1});
      ans.push_back({0, 0});
    } else {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (i % 2 == 0)
            ans.push_back({i, j});
          else
            ans.push_back({i, m - j - 1});
        }
      }
      ans.push_back({0, 0});
      cout << "1\n";
      cout << n << " " << m << " "
           << "1 1\n";
    }
  } else if (n % 2 == 0) {
    cout << "0\n";
    ans.push_back({0, 0});
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < m - 1; j++) {
        if (i & 1)
          ans.push_back({i, j});
        else
          ans.push_back({i, m - j - 2});
      }
    }
    for (int i = n - 1; i >= 0; i--) ans.push_back({i, m - 1});
    for (int i = m - 2; i >= 0; i--) ans.push_back({0, i});
  } else {
    cout << "0\n";
    ans.push_back({0, 0});
    for (int i = 1; i < m; i++) {
      for (int j = 0; j < n - 1; j++) {
        if (i & 1)
          ans.push_back({j, i});
        else
          ans.push_back({n - j - 2, i});
      }
    }
    for (int i = m - 1; i >= 0; i--) ans.push_back({n - 1, i});
    for (int i = n - 2; i >= 0; i--) ans.push_back({i, 0});
  }
  for (auto it : ans) cout << it.first + 1 << " " << it.second + 1 << "\n";
}
