#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > solveEven(int n, int m) {
  vector<pair<int, int> > ans;
  int i = 1, j = 1;
  for (; i < n; i++) {
    ans.push_back(make_pair(i, j));
  }
  while (1) {
    for (; j <= m; j++) ans.push_back(make_pair(i, j));
    j--;
    i--;
    for (; j > 1; j--) ans.push_back(make_pair(i, j));
    j++;
    i--;
    if (i == 0) break;
  }
  i++;
  ans.push_back(make_pair(1, 1));
  return ans;
}
vector<pair<int, int> > solveOdd(int n, int m) {
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; i += 2) {
    for (int j = 1; j <= m; j++) ans.push_back(make_pair(i, j));
    if (i != n)
      for (int j = m; j > 0; j--) ans.push_back(make_pair(i + 1, j));
  }
  ans.push_back(make_pair(1, 1));
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n == 1 and m > 2) {
    cout << 1 << endl;
    cout << n << " " << m << " " << 1 << " " << 1 << endl;
    for (int j = 1; j <= m; j++) cout << 1 << " " << j << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  if (m == 1 and n > 2) {
    cout << 1 << endl;
    cout << n << " " << m << " " << 1 << " " << 1 << endl;
    for (int i = 1; i <= n; i++) cout << i << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  if (n % 2 == 0) {
    vector<pair<int, int> > ans = solveEven(n, m);
    cout << 0 << endl;
    for (int i = 0; i < (int)ans.size(); i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  } else if (m % 2 == 0) {
    vector<pair<int, int> > ans = solveEven(m, n);
    cout << 0 << endl;
    for (int i = 0; i < (int)ans.size(); i++)
      cout << ans[i].second << " " << ans[i].first << endl;
  } else {
    cout << 1 << endl;
    cout << n << " " << m << " " << 1 << " " << 1 << endl;
    vector<pair<int, int> > ans = solveOdd(n, m);
    for (int i = 0; i < (int)ans.size(); i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  }
}
