#include <bits/stdc++.h>
const int PI = acos(-1.0);
using namespace std;
const int Max = 10055;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
bool com(string x, string y) { return x + y < y + x; }
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) return cout << 0 << endl << 1 << " " << 1, 0;
  if (n == 1 && m == 2) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 1 << " " << 2 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  if (n == 2 && m == 1) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 2 << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  if (n % 2 == 0 && m % 2 == 0 ||
      n % 2 != 0 && m % 2 == 0 && n != 1 && m != 1) {
    cout << 0 << endl;
    for (int j = 1; j <= n; j++) cout << j << " " << 1 << endl;
    for (int i = 2; i <= m; i++) {
      if (i % 2 != 0)
        for (int j = 2; j <= n; j++) cout << j << " " << i << endl;
      else
        for (int j = n; j >= 2; j--) cout << j << " " << i << endl;
    }
    for (int i = m; i >= 1; i--) cout << 1 << " " << i << endl;
  } else if (n % 2 != 0 && m % 2 != 0 || n == 1 || m == 1) {
    cout << 1 << endl << n << " " << m << " " << 1 << " " << 1 << endl;
    for (int i = 1; i <= n; i++) {
      if (i % 2 != 0)
        for (int j = 1; j <= m; j++) cout << i << " " << j << endl;
      else
        for (int j = m; j >= 1; j--) cout << i << " " << j << endl;
    }
    cout << 1 << " " << 1;
  } else {
    cout << 0 << endl;
    for (int j = 1; j <= n; j++) cout << j << " " << 1 << endl;
    for (int i = n; i > 1; i--) {
      if (i % 2 == 0)
        for (int j = 2; j <= m; j++) cout << i << " " << j << endl;
      else
        for (int j = m; j >= 2; j--) cout << i << " " << j << endl;
    }
    for (int i = m; i > 0; i--) cout << 1 << " " << i << endl;
  }
  return 0;
}
