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