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