#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  scanf("%lld", &n);
  scanf("%lld", &m);
  long long int i, j;
  if (n == 1 && m == 2) {
    cout << "0\n1 1\n1 2\n1 1\n";
  } else if (n == 2 && m == 1) {
    cout << "0\n1 1\n2 1\n1 1\n";
  } else if ((n % 2 == 0 || m % 2 == 0) && (n != 1 && m != 1)) {
    cout << "0\n";
    if (n % 2 == 0) {
      for (i = 1; i <= m; i++) {
        cout << 1 << " " << i << "\n";
      }
      long long int st, en, inc;
      for (i = 2; i <= n; i++) {
        if (i % 2 != 0) {
          st = 2;
          en = m + 1;
          inc = 1;
        } else {
          st = m;
          en = 1;
          inc = -1;
        }
        for (j = st; j != en; j += inc) {
          cout << i << " " << j << "\n";
        }
      }
      for (j = n; j >= 1; j--) {
        cout << j << " " << 1 << "\n";
      }
    } else {
      for (i = 1; i <= n; i++) {
        cout << i << " " << 1 << "\n";
      }
      long long int st, inc, en;
      for (i = 2; i <= m; i++) {
        if (i % 2 != 0) {
          st = 2;
          en = n + 1;
          inc = 1;
        } else {
          st = n;
          en = 1;
          inc = -1;
        }
        for (j = st; j != en; j += inc) {
          cout << j << " " << i << "\n";
        }
      }
      for (j = m; j >= 1; j--) {
        cout << 1 << " " << j << "\n";
      }
    }
  } else {
    cout << "1\n" << n << " " << m << " 1 1\n";
    for (i = 1; i <= n; i++) {
      long long int st, en, inc;
      if (i % 2 != 0) {
        st = 1;
        en = m + 1;
        inc = 1;
      } else {
        st = m;
        en = 0;
        inc = -1;
      }
      for (j = st; j != en; j += inc) {
        cout << i << " " << j << "\n";
      }
    }
    cout << "1 1\n";
  }
}
