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