#include <bits/stdc++.h>
using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
const long double PI = 3.141592653589793;
const long long INF = 9223372036854775807ll;
const long long mod = 1e9 + 7;
int n, m;
void solve() {
  cin >> n >> m;
  if (n == 1 && m == 2) {
    cout << 0 << '\n';
    cout << 1 << " " << 1 << '\n';
    cout << 1 << " " << 2 << '\n';
    cout << 1 << " " << 1 << '\n';
    return;
  }
  if (n == 2 && m == 1) {
    cout << 0 << '\n';
    cout << 1 << " " << 1 << '\n';
    cout << 2 << " " << 1 << '\n';
    cout << 1 << " " << 1 << '\n';
    return;
  }
  if (n == 1) {
    cout << 1 << '\n';
    cout << 1 << " " << m << " " << 1 << " " << 1 << '\n';
    for (int i = 1; i <= m; ++i) {
      cout << 1 << " " << i << '\n';
    }
    cout << 1 << " " << 1 << '\n';
  } else if (m == 1) {
    cout << 1 << '\n';
    cout << n << " " << 1 << " " << 1 << " " << 1 << '\n';
    for (int i = 1; i <= n; ++i) {
      cout << i << " " << 1 << '\n';
    }
    cout << 1 << " " << 1 << '\n';
  } else if (!(n % 2)) {
    cout << 0 << '\n';
    cout << 1 << " " << 1 << '\n';
    for (int i = 1; i <= n; ++i) {
      if (i % 2) {
        for (int j = 2; j <= m; ++j) {
          cout << i << " " << j << '\n';
        }
      } else {
        for (int j = m; j >= 2; --j) {
          cout << i << " " << j << '\n';
        }
      }
    }
    for (int i = n; i >= 1; --i) {
      cout << i << " " << 1 << '\n';
    }
  } else if (!(m % 2)) {
    cout << 0 << '\n';
    cout << 1 << " " << 1 << '\n';
    for (int j = 1; j <= m; ++j) {
      if (j % 2) {
        for (int i = 2; i <= n; ++i) {
          cout << i << " " << j << '\n';
        }
      } else {
        for (int i = n; i >= 2; --i) {
          cout << i << " " << j << '\n';
        }
      }
    }
    for (int j = m; j >= 1; --j) {
      cout << 1 << " " << j << '\n';
    }
  } else {
    cout << 1 << '\n';
    cout << n << " " << m << " " << 1 << " " << 1 << '\n';
    for (int j = 1; j <= m; ++j) {
      if (j % 2) {
        for (int i = 1; i <= n; ++i) {
          cout << i << " " << j << '\n';
        }
      } else {
        for (int i = n; i >= 1; --i) {
          cout << i << " " << j << '\n';
        }
      }
    }
    cout << 1 << " " << 1 << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  solve();
  return 0;
}
