#include <bits/stdc++.h>
using namespace std;
int n, m;
void horizontal_snake(int ending_row, int ending_col) {
  int act_col = 2;
  while (act_col <= ending_col) {
    for (int row = 1; row <= ending_row; ++row)
      cout << row << ' ' << act_col << '\n';
    act_col++;
    if (act_col > ending_col) break;
    for (int row = ending_row; row >= 1; --row)
      cout << row << ' ' << act_col << '\n';
    act_col++;
  }
}
void vertical_snake(int ending_row, int ending_col) {
  int act_row = 2;
  while (act_row <= ending_row) {
    for (int col = 1; col <= ending_col; ++col)
      cout << act_row << ' ' << col << '\n';
    act_row++;
    if (act_row > ending_row) break;
    for (int col = ending_col; col >= 1; --col)
      cout << act_row << ' ' << col << '\n';
    act_row++;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  if (n == 1 && m == 2) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    cout << 1 << ' ' << 2 << '\n';
    cout << 1 << ' ' << 1 << '\n';
  } else if (n == 2 && m == 1) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    cout << 2 << ' ' << 1 << '\n';
    cout << 1 << ' ' << 1 << '\n';
  } else if (n == 1) {
    cout << 1 << '\n';
    cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << '\n';
    for (int col = 1; col <= m; ++col) cout << 1 << ' ' << col << '\n';
    cout << 1 << ' ' << 1 << '\n';
  } else if (m == 1) {
    cout << 1 << '\n';
    cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << '\n';
    for (int row = 1; row <= n; ++row) cout << row << ' ' << 1 << '\n';
    cout << 1 << ' ' << 1 << '\n';
  } else if (n % 2 == 0) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    vertical_snake(n, m - 1);
    for (int r = n; r >= 1; --r) cout << r << ' ' << m << '\n';
    for (int c = m - 1; c >= 1; --c) cout << 1 << ' ' << c << '\n';
  } else if (m % 2 == 0) {
    cout << 0 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    horizontal_snake(n - 1, m);
    for (int c = m; c >= 1; --c) cout << n << ' ' << c << '\n';
    for (int r = n - 1; r >= 1; --r) cout << r << ' ' << 1 << '\n';
  } else {
    cout << 1 << '\n';
    cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << '\n';
    int act_row = 1;
    while (act_row <= n) {
      for (int col = 1; col <= m; ++col) cout << act_row << ' ' << col << '\n';
      act_row++;
      if (act_row > n) break;
      for (int col = m; col >= 1; --col) cout << act_row << ' ' << col << '\n';
      act_row++;
    }
    cout << 1 << ' ' << 1 << '\n';
  }
  return 0;
}
