#include <bits/stdc++.h>
using namespace std;
const int e9 = 1000 * 1000 * 1000;
const long long e18 = (long long)e9 * (long long)e9;
const double pi = 3.1415926535;
void pV(int num) { cout << num << " "; }
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
double rd() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long rll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
string rs() {
  string x;
  cin >> x;
  return x;
}
string rsf() {
  string s;
  char c;
  while (c = getchar()) {
    if (c >= 65 && c <= 90 || c >= 'a' && c <= 'z')
      s += c;
    else
      break;
  }
  return s;
}
void wi(int x) { printf("%d ", x); }
void wd(double x) { printf("%lf ", x); }
void wll(long long x) { printf("%lld ", x); }
void ws(string x) { cout << x << " "; }
int main() {
  int n = ri(), m = ri();
  if (m == 2) {
    cout << 0 << endl;
    cout << 1 << ' ' << 1 << endl;
    for (int i = (int)(1); i <= (int)(n); i++) cout << i << ' ' << 2 << endl;
    for (int i = (int)(n); i >= (int)(1); i--) cout << i << ' ' << 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 == 1) {
    cout << 1 << endl << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
    for (int i = (int)(1); i <= (int)(m); i++) cout << 1 << ' ' << i << endl;
    cout << 1 << ' ' << 1;
    return 0;
  }
  if (m == 1) {
    cout << 1 << endl << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
    for (int i = (int)(1); i <= (int)(n); i++) cout << i << ' ' << 1 << endl;
    cout << 1 << ' ' << 1;
    return 0;
  }
  if (n & 1 && m & 1) {
    cout << 1 << endl << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
    bool r = true;
    int q = 1;
    int j = 0;
    while (1) {
      if (q == 1) {
        j++;
        r = true;
        wi(j);
        wi(q);
        cout << endl;
      }
      if (q == m) {
        j++;
        r = false;
        wi(j);
        wi(q);
        cout << endl;
      }
      if (r)
        q++;
      else
        q--;
      wi(j);
      wi(q);
      cout << endl;
      if (j == n && q == m) break;
    }
    cout << 1 << ' ' << 1;
  } else if (n & 1) {
    bool r = true;
    int i = 1;
    int j = 1;
    cout << 0 << endl;
    for (int k = (int)(1); k <= (int)(n); k++) cout << k << ' ' << 1 << endl;
    j = 1;
    i = n;
    while (1) {
      if (i == 2) {
        j++;
        r = true;
        wi(i);
        wi(j);
        cout << endl;
      }
      if (i == n) {
        j++;
        r = false;
        wi(i);
        wi(j);
        cout << endl;
      }
      if (r)
        i++;
      else
        i--;
      wi(i);
      wi(j);
      cout << endl;
      if (i == 2 && j == m) break;
    }
    for (int k = (int)(m); k >= (int)(1); k--) cout << 1 << ' ' << k << endl;
  } else {
    cout << 0 << endl << 1 << ' ' << 1 << endl;
    int i = 1;
    int j = 2;
    bool r = true;
    while (1) {
      cout << i << ' ' << j << endl;
      if (r)
        j++;
      else
        j--;
      if (j == 2) {
        r = true;
        cout << i << ' ' << j << endl;
        if (i == n && j == 2) break;
        i++;
      }
      if (j == m) {
        r = false;
        cout << i << ' ' << j << endl;
        if (i == n && j == 2) break;
        i++;
      }
    }
    for (int i = (int)(n); i >= (int)(1); i--) cout << i << ' ' << 1 << endl;
  }
  return 0;
}
