#include <bits/stdc++.h>
using namespace std;
int N, M;
void Solve_1() {
  cout << "0\n1 1" << endl;
  for (int i = 1; i <= N; i++)
    if (i % 2 != 0) {
      for (int j = 2; j <= M; j++) cout << i << " " << j << endl;
    } else
      for (int j = M; j >= 2; j--) cout << i << " " << j << endl;
  for (int i = N; i >= 1; i--) cout << i << " 1" << endl;
}
void Solve_2() {
  cout << "0\n1 1" << endl;
  for (int i = 1; i <= M; i++)
    if (i % 2 != 0) {
      for (int j = 2; j <= N; j++) cout << j << " " << i << endl;
    } else
      for (int j = N; j >= 2; j--) cout << j << " " << i << endl;
  for (int i = M; i >= 1; i--) cout << "1 " << i << endl;
}
void Solve_3() {
  cout << "1\n" << N << " " << M << " 1 1" << endl;
  for (int i = 1; i <= N; i++)
    if (i % 2 != 0) {
      for (int j = 1; j <= M; j++) cout << i << " " << j << endl;
    } else {
      for (int j = M; j >= 1; j--) cout << i << " " << j << endl;
    }
  cout << "1 1" << endl;
}
int main(int argc, char** argv) {
  cin >> N >> M;
  if ((N % 2 == 0 && M != 1) || (N == 2 && M == 1))
    Solve_1();
  else if ((M % 2 == 0 && N != 1) || (M == 2 && N == 1))
    Solve_2();
  else
    Solve_3();
  return 0;
}
