#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  bool d = true, b = false, s = false;
  cin >> n >> m;
  if ((n % 2 == 0 && m > 1) || (n % 2 == 1 && m % 2 == 1 && n < m) || n == 1) {
    s = true;
    int tmp = n;
    n = m;
    m = tmp;
  }
  if ((m > 1 && m % 2) || (n > 2 && m == 1)) {
    cout << 1 << "\n";
    if (!s)
      cout << n << " " << m << " " << 1 << " " << m << "\n";
    else
      cout << m << " " << n << " " << m << " " << 1 << "\n";
  } else {
    cout << 0 << "\n";
  }
  int i = 1, j = 1;
  while (true) {
    if (s)
      cout << j << " " << i << "\n";
    else
      cout << i << " " << j << "\n";
    if (!b) {
      if (j == m && ((d && i == n) || (!d && i == 2))) {
        i = 1;
        b = true;
        continue;
      }
      if ((d && i == n) || (!d && i == 2)) {
        j++;
        d = !d;
        continue;
      }
      if (d) {
        i++;
      } else {
        i--;
      }
    } else {
      if (i == 1 && j == 1) break;
      j--;
    }
  }
  return 0;
}
