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