#include <bits/stdc++.h>
using namespace std;
const long long int inf = 2E+9;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long 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 (m == 1 && n == 2) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 2 << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << 1 << endl;
    cout << 1 << " " << m << " " << 1 << " " << 1 << endl;
    for (long long int i = 1; i <= m; i++) cout << 1 << " " << i << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  } else if (m == 1) {
    cout << 1 << endl;
    cout << n << " " << 1 << " " << 1 << " " << 1 << endl;
    for (long long int i = 1; i <= n; i++) cout << i << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  if (n % 2 == 0) {
    cout << 0 << endl;
    for (long long int i = 1; i <= n; i++) cout << i << " " << 1 << endl;
    for (long long int i = n; i >= 1; i--) {
      if ((n - i) % 2 == 0) {
        for (long long int j = 2; j <= m; j++) cout << i << " " << j << endl;
      } else {
        for (long long int j = m; j >= 2; j--) {
          cout << i << " " << j << endl;
        }
      }
    }
  } else if (m % 2 == 0) {
    cout << 0 << endl;
    for (long long int j = 1; j <= m; j++) cout << 1 << " " << j << endl;
    for (long long int j = m; j >= 1; j--) {
      if ((m - j) % 2 == 0) {
        for (long long int i = 2; i <= n; i++) cout << i << " " << j << endl;
      } else {
        for (long long int i = n; i >= 2; i--) {
          cout << i << " " << j << endl;
        }
      }
    }
  } else {
    cout << 1 << endl;
    cout << 1 << " " << m << " " << 1 << " " << 1 << endl;
    for (long long int i = 1; i <= n; i++) cout << i << " " << 1 << endl;
    for (long long int i = n; i >= 1; i--) {
      if ((n - i) % 2 == 0) {
        for (long long int j = 2; j <= m; j++) cout << i << " " << j << endl;
      } else {
        for (long long int j = m; j >= 2; j--) {
          cout << i << " " << j << endl;
        }
      }
    }
  }
  cout << 1 << " " << 1 << endl;
}
