#include <bits/stdc++.h>
using namespace std;
struct pole {
  int x, y;
};
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<pole> odp;
  bool zam = false;
  if (n == 1 || m == 1) {
    if (m == 1) {
      swap(n, m);
      zam = true;
    }
    if (m == 2) {
      cout << "0" << endl;
      odp.push_back({0, 0});
      odp.push_back({0, 1});
      odp.push_back({0, 0});
    } else {
      cout << "1" << endl;
      if (!zam)
        cout << "1 " << m << " 1 1" << endl;
      else
        cout << m << " 1 1 1" << endl;
      for (int i = 0, j = 0; j < m; ++j) odp.push_back({i, j});
      odp.push_back({0, 0});
    }
  } else {
    if (n % 2 == 0 || m % 2 == 0) {
      cout << "0" << endl;
      if (n % 2 == 0) {
        swap(n, m);
        zam = true;
      }
      for (int i = 0, j = 0; j < m; ++j) odp.push_back({i, j});
      for (int j = m - 1; j >= 0; --j) {
        if (j % 2 == 1) {
          for (int i = 1; i < n; ++i) odp.push_back({i, j});
        } else {
          for (int i = n - 1; i >= 1; --i) odp.push_back({i, j});
        }
      }
      odp.push_back({0, 0});
    } else {
      cout << "1" << endl;
      cout << n << " 1 1 1" << endl;
      for (int i = 0, j = 0; j < m; ++j) odp.push_back({i, j});
      for (int j = m - 1; j >= 0; --j) {
        if (j % 2 == 0) {
          for (int i = 1; i < n; ++i) odp.push_back({i, j});
        } else {
          for (int i = n - 1; i >= 1; --i) odp.push_back({i, j});
        }
      }
      odp.push_back({0, 0});
    }
  }
  for (int i = 0; i < odp.size(); ++i) {
    if (zam) swap(odp[i].x, odp[i].y);
    cout << odp[i].x + 1 << " " << odp[i].y + 1 << endl;
  }
  return 0;
}
