#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vp;
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 1 << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
  } else if (n == 1) {
    if (m == 2) {
      cout << 0 << endl;
      cout << 1 << " " << 1 << endl;
      cout << 1 << " " << 2 << endl;
      cout << 1 << " " << 1 << endl;
    } else {
      cout << 1 << endl;
      cout << 1 << " " << m << " " << 1 << " " << 1 << endl;
      for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl;
      cout << 1 << " " << 1 << endl;
    }
  } else if (m == 1) {
    if (n == 2) {
      cout << 0 << endl;
      cout << 1 << " " << 1 << endl;
      cout << 2 << " " << 1 << endl;
      cout << 1 << " " << 1 << endl;
    } else {
      cout << 1 << endl;
      cout << n << " " << 1 << " " << 1 << " " << 1 << endl;
      for (int i = 1; i <= n; i++) cout << i << " " << 1 << endl;
      cout << 1 << " " << 1 << endl;
    }
  } else if (n * m % 2) {
    int ex, ey;
    cout << 1 << endl;
    int dir = 1;
    for (int i = 1; i <= n; i++) {
      if (dir == 1) {
        for (int j = 1; j <= m; j++) {
          vp.push_back(make_pair(i, j));
          ex = i;
          ey = j;
        }
      } else {
        for (int j = m; j >= 1; j--) {
          vp.push_back(make_pair(i, j));
          ex = i;
          ey = j;
        }
      }
      dir = -dir;
    }
    cout << ex << " " << ey << " " << 1 << " " << 1 << endl;
    for (int i = 0; i < vp.size(); i++)
      cout << vp[i].first << " " << vp[i].second << endl;
    cout << 1 << " " << 1 << endl;
  } else {
    if (n % 2 == 0) {
      cout << 0 << endl;
      cout << 1 << " " << 1 << endl;
      int dir = 1;
      for (int i = 1; i <= n; i++) {
        if (dir == 1) {
          for (int j = 2; j <= m; j++) cout << i << " " << j << endl;
        } else {
          for (int j = m; j >= 2; j--) cout << i << " " << j << endl;
        }
        dir = -dir;
      }
      for (int i = n; i >= 1; i--) cout << i << " " << 1 << endl;
    } else {
      cout << 0 << endl;
      cout << 1 << " " << 1 << endl;
      int dir = 1;
      for (int i = 1; i <= m; i++) {
        if (dir == 1) {
          for (int j = 2; j <= n; j++) cout << j << " " << i << endl;
        } else {
          for (int j = n; j >= 2; j--) cout << j << " " << i << endl;
        }
        dir = -dir;
      }
      for (int i = m; i >= 1; i--) cout << 1 << " " << i << endl;
    }
  }
  return 0;
}
