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