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