#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:666000000")
using namespace std;
const int inf = (1 << 30) - 1;
const long double eps = 1e-9;
const long double pi = fabs(atan2(0.0, -1.0));
void ML(const bool v) {
  if (v) return;
  int *ass;
  for (;;) {
    ass = new int[2500000];
    for (int i = 0; i < 2500000; i++) ass[i] = rand();
  }
}
void TL(const bool v) {
  if (v) return;
  int *ass;
  ass = new int[250];
  for (;;) {
    for (int i = 0; i < 250; i++) ass[i] = rand();
  }
}
void PE(const bool v) {
  if (v) return;
  puts("ass 1 2 3 4 5 6 fuck");
  exit(0);
}
int n, m;
bool was[300][300];
void LoAd() { cin >> n >> m; }
vector<pair<int, int> > res;
bool swapped;
int x = 1, y = 1;
bool can_dn() { return !was[x + 1][y]; }
bool can_up() { return !was[x - 1][y]; }
bool can_lt() { return !was[x][y - 1]; }
bool can_rt() { return !was[x][y + 1]; }
void go_dn() {
  res.push_back(make_pair(x, y));
  was[x][y] = true;
  x++;
}
void go_up() {
  res.push_back(make_pair(x, y));
  was[x][y] = true;
  x--;
}
void go_lt() {
  res.push_back(make_pair(x, y));
  was[x][y] = true;
  y--;
}
void go_rt() {
  res.push_back(make_pair(x, y));
  was[x][y] = true;
  y++;
}
void SoLvE() {
  if (min(n, m) == 1 && max(n, m) == 2) {
    puts("0");
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) printf("%d %d\n", i, j);
    printf("1 1");
    return;
  }
  if (n == 1 || m == 1) {
    puts("1");
    printf("%d %d %d %d\n", n, m, 1, 1);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) printf("%d %d\n", i, j);
    printf("1 1");
    return;
  }
  if (n % 2 == 0 && m % 2 == 1) {
    swap(n, m);
    swapped = true;
  }
  for (int i = 0; i < 300; i++)
    for (int j = 0; j < 300; j++)
      if (1 <= i && i <= n && 1 <= j && j <= m)
        was[i][j] = false;
      else
        was[i][j] = true;
  if (1 == n % 2 && 1 == m % 2) {
    puts("1");
    printf("%d %d %d %d\n", n, m, 1, 1);
    while (x != n || y != m) {
      while (can_dn()) go_dn();
      if (can_rt()) go_rt();
      while (can_up()) go_up();
      if (can_rt()) go_rt();
    }
    res.push_back(make_pair(n, m));
    res.push_back(make_pair(1, 1));
  } else {
    puts("0");
    while (true) {
      while (can_dn()) go_dn();
      if (can_rt()) go_rt();
      if (x == n && y == m) break;
      while (can_up() && x > 2) go_up();
      if (can_rt()) go_rt();
    }
    while (can_up()) go_up();
    while (can_lt()) go_lt();
    res.push_back(make_pair(x, y));
    res.push_back(make_pair(1, 1));
  }
  for (int i = 0; i < (int)res.size(); i++) {
    if (swapped) swap(res[i].first, res[i].second);
    printf("%d %d\n", res[i].first, res[i].second);
  }
}
int main() {
  srand((int)time(NULL));
  LoAd();
  SoLvE();
  return 0;
}
