#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  if (n == 1) {
    if (m == 2) {
      cout << "0\n1 1\n1 2\n1 1\n";
      return 0;
    }
    cout << "1\n";
    cout << n << " " << m << " 1 1\n";
    for (int i = 1; i <= m; i++) {
      cout << "1 " << i << '\n';
    }
    cout << "1 1\n";
    return 0;
  }
  if (m == 1) {
    if (n == 2) {
      cout << "0\n1 1\n2 1\n1 1\n";
      return 0;
    }
    cout << "1\n";
    cout << n << " " << m << " 1 1\n";
    for (int i = 1; i <= n; i++) {
      cout << i << " 1\n";
    }
    cout << "1 1\n";
    return 0;
  }
  if (n % 2 == 0) {
    cout << "0\n";
    for (int i = 1; i <= m; i++) {
      cout << "1 " << i << '\n';
    }
    for (int i = 2; i <= n; i++) {
      if (i % 2 == 0) {
        for (int j = m; j >= 2; --j) {
          cout << i << ' ' << j << '\n';
        }
      } else {
        for (int j = 2; j <= m; j++) {
          cout << i << ' ' << j << '\n';
        }
      }
    }
    for (int i = n; i >= 1; --i) {
      cout << i << " 1\n";
    }
    return 0;
  }
  if (m % 2 == 0) {
    cout << "0\n";
    for (int i = 1; i <= n; i++) {
      cout << i << " 1\n";
    }
    for (int i = 2; i <= m; i++) {
      if (i % 2 == 0) {
        for (int j = n; j >= 2; --j) {
          cout << j << ' ' << i << '\n';
        }
      } else {
        for (int j = 2; j <= n; j++) {
          cout << j << ' ' << i << '\n';
        }
      }
    }
    for (int i = m; i >= 1; --i) {
      cout << "1 " << i << "\n";
    }
    return 0;
  }
  cout << "1\n";
  cout << n << " " << m << " 1 1\n";
  for (int i = 1; i <= n; i++) {
    if (i % 2) {
      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";
}
