#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9,
                inf = 1e18 + 7;
const long long infll = 1e18 + 7;
long long n, m;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  if (n == 1 && m == 2) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    cout << 1 << ' ' << 2 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    return 0;
  }
  if (n == 2 && m == 1) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    cout << 2 << ' ' << 1 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    return 0;
  }
  if (n == 1) {
    cout << 1 << '\n';
    cout << 1 << ' ' << m << ' ' << 1 << ' ' << 1 << '\n';
    for (long long j = 1; j <= m; j++) {
      cout << 1 << ' ' << j << '\n';
    }
    cout << 1 << ' ' << 1 << '\n';
    return 0;
  }
  if (m == 1) {
    cout << 1 << '\n';
    cout << n << ' ' << 1 << ' ' << 1 << ' ' << 1 << '\n';
    for (long long i = 1; i <= n; i++) {
      cout << i << ' ' << 1 << '\n';
    }
    cout << 1 << ' ' << 1 << '\n';
    return 0;
  }
  if (n % 2 == 0) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    for (long long i = 1; i <= n; i++) {
      if (i % 2 == 1) {
        for (long long j = 2; j <= m; j++) {
          cout << i << ' ' << j << '\n';
        }
      } else {
        for (long long j = m; j >= 2; j--) {
          cout << i << ' ' << j << '\n';
        }
      }
    }
    for (long long i = n; i >= 1; i--) {
      cout << i << ' ' << 1 << '\n';
    }
    return 0;
  }
  if (m % 2 == 0) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    for (long long j = 1; j <= m; j++) {
      if (j % 2 == 1) {
        for (long long i = 2; i <= n; i++) {
          cout << i << ' ' << j << '\n';
        }
      } else {
        for (long long i = n; i >= 2; i--) {
          cout << i << ' ' << j << '\n';
        }
      }
    }
    for (long long j = m; j >= 1; j--) {
      cout << 1 << ' ' << j << '\n';
    }
    return 0;
  }
  cout << 1 << '\n';
  cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << '\n';
  for (long long i = 1; i <= n; i++) {
    if (i % 2 == 1) {
      for (long long j = 1; j <= m; j++) {
        cout << i << ' ' << j << '\n';
      }
    } else {
      for (long long j = m; j >= 1; j--) {
        cout << i << ' ' << j << '\n';
      }
    }
  }
  cout << 1 << ' ' << 1 << '\n';
}
