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