#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
int main(void) {
  long long n, m;
  cin >> n >> m;
  if (n == 1 && m == 2) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 1 << " " << 2 << endl;
    cout << 1 << " " << 1 << endl;
    exit(0);
  }
  if (n == 2 && m == 1) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 2 << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    exit(0);
  }
  if (n == 1) {
    cout << 1 << endl;
    cout << 1 << " " << m << " " << 1 << " " << 1 << endl;
    for (long long(i) = 0; (i) < (long long)(m); (i)++)
      cout << 1 << " " << i + 1 << endl;
    cout << 1 << " " << 1 << endl;
    exit(0);
  }
  if (m == 1) {
    cout << 1 << endl;
    cout << n << " " << 1 << " " << 1 << " " << 1 << endl;
    for (long long(i) = 0; (i) < (long long)(n); (i)++)
      cout << i + 1 << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    exit(0);
  }
  if (n % 2 == 1 && m % 2 == 1) {
    cout << 1 << endl;
    cout << n << " " << m << " " << 1 << " " << 1 << endl;
    for (long long(i) = 0; (i) < (long long)(n); (i)++) {
      long long now = 1, x = 1;
      if (i & 1) now = m, x = -1;
      for (long long(j) = 0; (j) < (long long)(m); (j)++)
        cout << i + 1 << " " << now << endl, now += x;
    }
    cout << 1 << " " << 1 << endl;
    exit(0);
  }
  if (n % 2 == 0) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    for (long long(i) = 0; (i) < (long long)(n); (i)++) {
      long long now = 2, x = 1;
      if (i & 1) now = m, x = -1;
      for (long long(j) = 0; (j) < (long long)(m - 1); (j)++)
        cout << i + 1 << " " << now << endl, now += x;
    }
    for (long long(i) = 0; (i) < (long long)(n); (i)++)
      cout << n - i << " " << 1 << endl;
    exit(0);
  }
  if (m % 2 == 0) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    for (long long(i) = 0; (i) < (long long)(m); (i)++) {
      long long now = 2, x = 1;
      if (i & 1) now = n, x = -1;
      for (long long(j) = 0; (j) < (long long)(n - 1); (j)++)
        cout << now << " " << i + 1 << endl, now += x;
    }
    for (long long(i) = 0; (i) < (long long)(m); (i)++)
      cout << 1 << " " << m - i << endl;
    exit(0);
  }
  return 0;
}
