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