#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
void run() {
  int n, m;
  cin >> n >> m;
  if (n == 1 || m == 1) {
    if (n == 1 && m == 2 || n == 2 && m == 1)
      cout << 0 << endl;
    else {
      cout << 1 << endl;
      cout << n << " " << m << " " << 1 << " " << 1 << endl;
    }
    if (n == 1)
      for (int i = 0; i < m; i++) cout << 1 << " " << i + 1 << endl;
    else
      for (int i = 0; i < n; i++) cout << i + 1 << " " << m << endl;
    cout << 1 << " " << 1 << endl;
    return;
  }
  if (n % 2 == 0 || m % 2 == 0) {
    cout << 0 << endl;
    if (n % 2 == 0) {
      cout << 1 << " " << 1 << endl;
      for (int i = 0; i < n / 2; i++) {
        for (int j = 0; j < m - 1; j++)
          cout << i * 2 + 1 << " " << j + 2 << endl;
        for (int j = 0; j < m - 1; j++)
          cout << i * 2 + 2 << " " << m - j << endl;
      }
      for (int i = 0; i < n; i++) cout << n - i << " " << 1 << endl;
    } else {
      cout << 1 << " " << 1 << endl;
      for (int i = 0; i < m / 2; i++) {
        for (int j = 0; j < n - 1; j++)
          cout << j + 2 << " " << i * 2 + 1 << endl;
        for (int j = 0; j < n - 1; j++)
          cout << n - j << " " << i * 2 + 2 << endl;
      }
      for (int i = 0; i < m; i++) cout << 1 << " " << m - i << endl;
    }
  } else {
    cout << 1 << endl;
    cout << n << " " << m << " " << 1 << " " << 1 << endl;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        cout << i + 1 << " " << (i % 2 ? m - j : j + 1) << endl;
    cout << 1 << " " << 1 << endl;
  }
}
int main() { run(); }
