#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  if (n == 1 && m == 2)
    cout << 0 << "\n"
         << "1 1"
         << "\n"
         << "1 2"
         << "\n"
         << "1 1"
         << "\n";
  else if (n == 2 && m == 1)
    cout << 0 << "\n"
         << "1 1"
         << "\n"
         << "2 1"
         << "\n"
         << "1 1"
         << "\n";
  else if (n == 1) {
    cout << 1 << "\n"
         << "1 " << m << " 1 1"
         << "\n";
    for (int i = 1; i <= m; i++) cout << "1 " << i << "\n";
    cout << "1 1"
         << "\n";
  } else if (m == 1) {
    cout << 1 << "\n"
         << n << " 1"
         << " 1 1"
         << "\n";
    for (int i = 1; i <= n; i++)
      cout << i << " 1"
           << "\n";
    cout << "1 1"
         << "\n";
  } else if (n % 2 == 0) {
    cout << 0 << "\n"
         << "1 1"
         << "\n";
    for (int i = 1; i <= n; i++) {
      if (i % 2 == 1)
        for (int j = 2; j <= m; j++) cout << i << " " << j << "\n";
      else
        for (int j = m; j >= 2; j--) cout << i << " " << j << "\n";
    }
    for (int i = n; i >= 1; i--)
      cout << i << " 1"
           << "\n";
  } else if (m % 2 == 0) {
    cout << 0 << "\n"
         << "1 1"
         << "\n";
    for (int i = 1; i <= m; i++) {
      if (i % 2 == 1)
        for (int j = 2; j <= n; j++) cout << j << " " << i << "\n";
      else
        for (int j = n; j >= 2; j--) cout << j << " " << i << "\n";
    }
    for (int i = m; i >= 1; i--) cout << "1 " << i << "\n";
  } else {
    cout << 1 << "\n"
         << n << " " << m << " 1 1"
         << "\n";
    for (int i = 1; i <= n; i++) {
      if (i % 2 == 1)
        for (int j = 1; j <= m; j++) cout << i << " " << j << "\n";
      else
        for (int j = m; j >= 1; j--) cout << i << " " << j << "\n";
    }
    cout << "1 1"
         << "\n";
  }
  return 0;
}
