#include <bits/stdc++.h>
using namespace std;
int n, m, k = 0, row, col;
vector<pair<int, int>> p;
vector<int> t(4);
void mv() { p.push_back({row, col}); }
void start() {
  row = col = 1;
  mv();
}
void up(int x) {
  for (int i = 0; i < x; i++) row--, mv();
}
void down(int x) {
  for (int i = 0; i < x; i++) row++, mv();
}
void left(int x) {
  for (int i = 0; i < x; i++) col--, mv();
}
void right(int x) {
  for (int i = 0; i < x; i++) col++, mv();
}
void teleport() {
  k = 1;
  t[0] = row;
  t[1] = col;
  t[2] = t[3] = row = col = 1;
  mv();
}
ostream& operator<<(ostream& os, const vector<int>& a) {
  for (auto x : a) os << x << " ";
  return os;
}
ostream& operator<<(ostream& os, const vector<pair<int, int>>& a) {
  for (const auto& x : a) os << x.first << " " << x.second << endl;
  return os;
}
int main() {
  cin >> n >> m;
  start();
  if (n == 1)
    right(m - 1), m == 2 ? left(1) : teleport();
  else if (m == 1)
    down(n - 1), n == 2 ? up(1) : teleport();
  else if (n == 2 || m == 2)
    right(m - 1), down(n - 1), left(m - 1), up(n - 1);
  else if (n % 2 == 0) {
    right(m - 1);
    down(1);
    while (row < n) left(m - 2), down(1), right(m - 2), down(1);
    left(m - 1), up(n - 1);
  } else if (m % 2 == 0) {
    down(n - 1);
    right(1);
    while (col < m) up(n - 2), right(1), down(n - 2), right(1);
    up(n - 1), left(m - 1);
  } else {
    right(m - 1);
    while (row < n) down(1), left(m - 1), down(1), right(m - 1);
    teleport();
  }
  cout << k << endl;
  if (k) cout << t << endl;
  cout << p;
}
