#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
  cin >> n >> m;
  if (m * n % 2 || ((min(m, n) == 1) && max(m, n) > 2)) {
    cout << 1 << '\n';
    cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << '\n';
    for (int i = 1; i <= m; ++i) {
      if (i % 2) {
        for (int j = 1; j <= n; ++j) cout << j << ' ' << i << '\n';
      } else {
        for (int j = n; j >= 1; --j) cout << j << ' ' << i << '\n';
      }
    }
    cout << 1 << ' ' << 1;
  } else {
    cout << 0 << '\n';
    if (n % 2 == 0) {
      for (int i = 1; i <= m; ++i) cout << 1 << ' ' << i << '\n';
      for (int i = 2; i <= n; ++i) {
        if (i % 2) {
          for (int j = 2; j <= m; ++j) cout << i << ' ' << j << '\n';
        } else {
          for (int j = m; j >= 2; --j) cout << i << ' ' << j << '\n';
        }
      }
      for (int i = n; i >= 1; --i) cout << i << ' ' << 1 << '\n';
    } else {
      for (int i = 1; i <= n; ++i) cout << i << ' ' << 1 << '\n';
      for (int i = 2; i <= m; ++i) {
        if (i % 2) {
          for (int j = 2; j <= n; ++j) cout << j << ' ' << i << '\n';
        } else {
          for (int j = n; j >= 2; --j) cout << j << ' ' << i << '\n';
        }
      }
      for (int i = m; i >= 1; --i) cout << 1 << ' ' << i << '\n';
    }
  }
  return 0;
}
