#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
struct P {
  int x, y;
};
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << "0" << endl;
    cout << "1 1" << endl;
    cout << "1 1" << endl;
    return 0;
  }
  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 == 1 || m == 1) {
    cout << "1" << endl;
    cout << n << " " << m << " "
         << "1 1" << endl;
    if (n == 1) {
      for (int i = 0; i < m; i++) cout << n << " " << i + 1 << endl;
    } else {
      for (int i = 0; i < n; i++) cout << i + 1 << " " << m << endl;
    }
    cout << "1 1" << endl;
    return 0;
  }
  bool b[101][101];
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++) b[i][j] = true;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) b[i][j] = false;
  P tele = {-1, -1};
  vector<P> ret;
  int di = 0;
  if (n % 2 == 0) {
    cout << "0" << endl;
    for (int i = 0; i < n - 1; i++) cout << i + 1 << " " << 1 << endl;
    for (int i = 0; i < m; i++) cout << n << " " << i + 1 << endl;
    P c = {n, m};
    for (int i = 0; i < n - 1; i++) {
      c.x--;
      cout << c.x << " " << c.y << endl;
      if (i % 2 == 0) {
        for (int i = 0; i < m - 2; i++) {
          c.y--;
          cout << c.x << " " << c.y << endl;
        }
      } else {
        for (int i = 0; i < m - 2; i++) {
          c.y++;
          cout << c.x << " " << c.y << endl;
        }
      }
    }
  } else if (m % 2 == 0) {
    cout << "0" << endl;
    for (int i = 0; i < m - 1; i++) cout << 1 << " " << i + 1 << endl;
    for (int i = 0; i < n; i++) cout << i + 1 << " " << m << endl;
    P c = {n, m};
    for (int i = 0; i < m - 1; i++) {
      c.y--;
      cout << c.x << " " << c.y << endl;
      if (i % 2 == 0) {
        for (int i = 0; i < n - 2; i++) {
          c.x--;
          cout << c.x << " " << c.y << endl;
        }
      } else {
        for (int i = 0; i < n - 2; i++) {
          c.x++;
          cout << c.x << " " << c.y << endl;
        }
      }
    }
  } else {
    cout << "1" << endl;
    cout << n << " " << m << " 1 1" << endl;
    P c = {1, 1};
    for (int i = 0; i < m; i++) {
      cout << c.x << " " << c.y << endl;
      if (i % 2 == 0) {
        for (int i = 0; i < n - 1; i++) {
          c.x++;
          cout << c.x << " " << c.y << endl;
        }
      } else {
        for (int i = 0; i < n - 1; i++) {
          c.x--;
          cout << c.x << " " << c.y << endl;
        }
      }
      if (c.x == n && c.y == m) break;
      c.y++;
    }
  }
  cout << "1 1" << endl;
}
