#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long powm(long long base, long long exp, long long mod = 1000000007) {
  base %= mod;
  long long ans = 1;
  while (exp) {
    if (exp & 1LL) ans = (ans * base) % mod;
    exp >>= 1LL, base = (base * base) % mod;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  if (n % 2 == 0 && (m > 1) || n == 2) {
    cout << 0 << '\n';
    for (long long i = 1; i <= m; i++) cout << 1 << " " << i << '\n';
    for (long long i = 2; i <= n; i++) cout << i << " " << m << '\n';
    for (int i = n; i > 1; i--) {
      for (int j = 1; j < m; j++) {
        if (i % 2)
          cout << i << " " << j << '\n';
        else
          cout << i << " " << m - j << '\n';
      }
    }
    cout << 1 << " " << 1 << '\n';
    return 0;
  }
  if (m % 2 == 0 && (n > 1 || m == 2)) {
    cout << 0 << '\n';
    for (long long i = 1; i <= n; i++) cout << i << " " << 1 << '\n';
    for (long long i = 2; i <= m; i++) cout << n << " " << i << '\n';
    for (int i = m; i > 1; i--) {
      for (int j = 1; j < n; j++) {
        if (i % 2)
          cout << j << " " << i << '\n';
        else
          cout << n - j << " " << i << '\n';
      }
    }
    cout << 1 << " " << 1 << '\n';
    return 0;
  }
  cout << 1 << '\n';
  cout << n << " " << m << " " << 1 << " " << 1 << '\n';
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (i % 2)
        cout << i << " " << j << '\n';
      else
        cout << i << " " << m + 1 - j << '\n';
    }
  }
  cout << 1 << " " << 1 << '\n';
}
