#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > snakeG(int x1, int y1, int x2, int y2) {
  vector<pair<int, int> > res;
  int n = y2 - y1 + 1, m = x2 - x1 + 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i % 2 == 0) {
        res.push_back(make_pair(x1 + i, y1 + j));
      } else {
        res.push_back(make_pair(x1 + i, y2 - j));
      }
    }
  }
  return res;
}
vector<pair<int, int> > snakeV(int x1, int y1, int x2, int y2) {
  vector<pair<int, int> > res;
  int n = y2 - y1 + 1, m = x2 - x1 + 1;
  for (int j = 0; j < n; ++j) {
    for (int i = 0; i < m; ++i) {
      if (j % 2 == 0) {
        res.push_back(make_pair(x1 + i, y1 + j));
      } else {
        res.push_back(make_pair(x2 - i, y1 + j));
      }
    }
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 1) {
    if (n == 2) {
      cout << 0 << endl;
      cout << 1 << ' ' << 1 << endl;
      cout << 2 << ' ' << 1 << endl;
      cout << 1 << ' ' << 1 << endl;
      return 0;
    } else {
      cout << 1 << endl;
      cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
      for (int i = 1; i < n + 1; ++i) cout << i << ' ' << 1 << endl;
      cout << 1 << ' ' << 1 << endl;
      return 0;
    }
  }
  if (n == 1) {
    if (m == 2) {
      cout << 0 << endl;
      cout << 1 << ' ' << 1 << endl;
      cout << 1 << ' ' << 2 << endl;
      cout << 1 << ' ' << 1 << endl;
      return 0;
    } else {
      cout << 1 << endl;
      cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
      for (int i = 1; i < m + 1; ++i) cout << 1 << ' ' << i << endl;
      cout << 1 << ' ' << 1 << endl;
      return 0;
    }
  }
  if (n == m) {
    if (n % 2 == 0) {
      cout << 0 << endl;
      vector<pair<int, int> > res = snakeG(1, 2, n, m);
      cout << 1 << ' ' << 1 << endl;
      for (int i = 0; i < res.size(); ++i)
        cout << res[i].first << ' ' << res[i].second << endl;
      for (int i = n; i >= 1; --i) cout << i << ' ' << 1 << endl;
    } else {
      cout << 1 << endl;
      cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
      vector<pair<int, int> > res = snakeG(1, 1, n, m);
      for (int i = 0; i < res.size(); ++i)
        cout << res[i].first << ' ' << res[i].second << endl;
      cout << 1 << ' ' << 1 << endl;
    }
  } else {
    if (n > m) {
      if (m % 2 == 0) {
        if (n % 2 == 0) {
          cout << 0 << endl;
          vector<pair<int, int> > res = snakeG(1, 2, n, m);
          cout << 1 << ' ' << 1 << endl;
          for (int i = 0; i < res.size(); ++i)
            cout << res[i].first << ' ' << res[i].second << endl;
          for (int i = n; i >= 1; --i) cout << i << ' ' << 1 << endl;
        } else {
          cout << 0 << endl;
          vector<pair<int, int> > res = snakeG(1, 2, n - 2, m);
          vector<pair<int, int> > res1 = snakeV(n - 1, 1, n, m);
          reverse(res1.begin(), res1.end());
          cout << 1 << ' ' << 1 << endl;
          for (int i = 0; i < res.size(); ++i)
            cout << res[i].first << ' ' << res[i].second << endl;
          for (int i = 0; i < res1.size(); ++i)
            cout << res1[i].first << ' ' << res1[i].second << endl;
          for (int i = n - 2; i >= 1; --i) cout << i << ' ' << 1 << endl;
        }
      } else {
        if (n % 2 == 0) {
          cout << 0 << endl;
          vector<pair<int, int> > res = snakeG(1, 2, n, m);
          cout << 1 << ' ' << 1 << endl;
          for (int i = 0; i < res.size(); ++i)
            cout << res[i].first << ' ' << res[i].second << endl;
          for (int i = n; i >= 1; --i) cout << i << ' ' << 1 << endl;
        } else {
          cout << 1 << endl;
          cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
          vector<pair<int, int> > res = snakeG(1, 1, n, m);
          for (int i = 0; i < res.size(); ++i)
            cout << res[i].first << ' ' << res[i].second << endl;
          cout << 1 << ' ' << 1 << endl;
        }
      }
    } else {
      if (n % 2 == 0) {
        cout << 0 << endl;
        vector<pair<int, int> > res = snakeG(1, 2, n, m);
        cout << 1 << ' ' << 1 << endl;
        for (int i = 0; i < res.size(); ++i)
          cout << res[i].first << ' ' << res[i].second << endl;
        for (int i = n; i >= 1; --i) cout << i << ' ' << 1 << endl;
      } else {
        if (m % 2 == 0) {
          cout << 0 << endl;
          vector<pair<int, int> > res = snakeG(1, 2, n - 2, m);
          vector<pair<int, int> > res1 = snakeV(n - 1, 1, n, m);
          reverse(res1.begin(), res1.end());
          cout << 1 << ' ' << 1 << endl;
          for (int i = 0; i < res.size(); ++i)
            cout << res[i].first << ' ' << res[i].second << endl;
          for (int i = 0; i < res1.size(); ++i)
            cout << res1[i].first << ' ' << res1[i].second << endl;
          for (int i = n - 2; i >= 1; --i) cout << i << ' ' << 1 << endl;
        } else {
          cout << 1 << endl;
          cout << n << ' ' << m << ' ' << 1 << ' ' << 1 << endl;
          vector<pair<int, int> > res = snakeG(1, 1, n, m);
          for (int i = 0; i < res.size(); ++i)
            cout << res[i].first << ' ' << res[i].second << endl;
          cout << 1 << ' ' << 1 << endl;
        }
      }
    }
  }
  return 0;
}
