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