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