#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int main(void) {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int cpt = 0;
  if (n == 1 && m == 1) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl << 1 << " " << 1 << endl;
    return 0;
  }
  if (n == 1 && m >= 3) {
    cout << 1 << endl;
    cout << n << " " << m << " 1 1" << endl;
    for (int j = int(1); j < int(m + 1); ++j) cout << "1 " << j << endl;
    cout << "1 1" << endl;
    return 0;
  }
  if (m == 1 && n >= 3) {
    cout << 1 << endl;
    cout << n << " " << m << " 1 1" << endl;
    for (int i = int(1); i < int(n + 1); ++i) cout << i << " 1" << endl;
    cout << "1 1" << endl;
    return 0;
  }
  if (n % 2 == 0) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cpt++;
    for (int i = int(1); i < int(n + 1); ++i) {
      if (i % 2 == 1) {
        for (int j = int(2); j < int(m + 1); ++j) {
          cout << i << " " << j << endl;
          cpt++;
        }
      } else {
        for (int j = m; j > 1; j--) {
          cout << i << " " << j << endl;
          cpt++;
        }
      }
    }
    for (int i = n; i > 0; i--) {
      cout << i << " " << 1 << endl;
      cpt++;
    }
  } else if (m % 2 == 0) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cpt++;
    for (int j = int(1); j < int(m + 1); ++j) {
      if (j % 2 == 1) {
        for (int i = int(2); i < int(n + 1); ++i) {
          cout << i << " " << j << endl;
          cpt++;
        }
      } else {
        for (int i = n; i > 1; i--) {
          cout << i << " " << j << endl;
          cpt++;
        }
      }
    }
    for (int j = m; j > 0; j--) {
      cout << 1 << " " << j << endl;
      cpt++;
    }
  } else {
    cout << 1 << endl;
    cout << n << " " << m << " " << 1 << " " << 1 << endl;
    for (int i = int(1); i < int(n + 1); ++i) {
      if (i % 2 == 1) {
        for (int j = int(1); j < int(m + 1); ++j) {
          cout << i << " " << j << endl;
          cpt++;
        }
      } else {
        for (int j = m; j > 0; j--) {
          cout << i << " " << j << endl;
          cpt++;
        }
      }
    }
    cout << 1 << " " << 1 << endl;
    cpt++;
  }
}
