#include <bits/stdc++.h>
using namespace std;
const int pinf = 2000000000;
const int minf = -2000000000;
const double pi = 3.1415926;
int n, m;
bool d[1000][1000];
int main() {
  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < 1000; j++) {
      d[i][j] = 1;
    }
  }
  scanf("%d", &n);
  scanf("%d", &m);
  if (n == 1 && m == 2) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl << 1 << " " << 2 << endl << 1 << " " << 1;
    return 0;
  }
  if (n == 2 && m == 1) {
    cout << 0 << endl;
    cout << 1 << " " << 1 << endl << 2 << " " << 1 << endl << 1 << " " << 1;
    return 0;
  }
  if (n == 1 || m == 1) {
    cout << 1 << endl;
    if (n == 1) {
      cout << 1 << " " << m << " " << 1 << " " << 1 << endl;
      for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl;
      cout << 1 << " " << 1;
    } else {
      cout << n << " " << 1 << " " << 1 << " " << 1 << endl;
      for (int i = 1; i <= n; i++) cout << i << " " << 1 << endl;
      cout << 1 << " " << 1;
    }
    return 0;
  }
  int ct = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if ((i + j) % 2 == 1)
        ct++;
      else
        ct--;
      d[i][j] = false;
    }
  }
  if (n % 2 == 0) {
    if (ct == 0) {
      cout << 0 << endl;
      for (int i = 1; i < n; i++) {
        cout << i << " " << 1 << " " << endl;
        d[i][1] = true;
      }
      d[1][1] = false;
      int x = n;
      int y = 1;
      int nap = 0;
      while (x != 1 || y != 1) {
        d[x][y] = true;
        if (nap == 0) {
          cout << x << " " << y << endl;
          if (!d[x][y + 1])
            y++;
          else {
            x--;
            nap = 1;
          }
        } else {
          cout << x << " " << y << endl;
          if (!d[x][y - 1])
            y--;
          else {
            x--;
            nap = 0;
          }
        }
      }
      cout << x << " " << y << endl;
    } else {
      cout << 1 << endl;
      cout << 1 << " " << m << " " << 1 << " " << 1 << endl;
      for (int i = 1; i < n; i++) {
        cout << i << " " << 1 << " " << endl;
        d[i][1] = true;
      }
      d[1][1] = false;
      int x = n;
      int y = 1;
      int nap = 0;
      while (x != 1 || y != m) {
        d[x][y] = true;
        if (nap == 0) {
          cout << x << " " << y << endl;
          if (!d[x][y + 1])
            y++;
          else {
            x--;
            nap = 1;
          }
        } else {
          cout << x << " " << y << endl;
          if (!d[x][y - 1])
            y--;
          else {
            x--;
            nap = 0;
          }
        }
      }
      cout << x << " " << y << endl;
      cout << 1 << " " << 1;
    }
  } else {
    if (ct == 0) {
      cout << 0 << endl;
      for (int i = 1; i < m; i++) {
        cout << 1 << " " << i << " " << endl;
        d[1][i] = true;
      }
      d[1][1] = false;
      int x = 1;
      int y = m;
      int nap = 0;
      while (x != 1 || y != 1) {
        d[x][y] = true;
        if (nap == 0) {
          cout << x << " " << y << endl;
          if (!d[x + 1][y])
            x++;
          else {
            y--;
            nap = 1;
          }
        } else {
          cout << x << " " << y << endl;
          if (!d[x - 1][y])
            x--;
          else {
            y--;
            nap = 0;
          }
        }
      }
      cout << x << " " << y << endl;
    } else {
      cout << 1 << endl;
      cout << n << " " << 1 << " " << 1 << " " << 1 << endl;
      for (int i = 1; i < m; i++) {
        cout << 1 << " " << i << " " << endl;
        d[1][i] = true;
      }
      d[1][1] = false;
      int x = 1;
      int y = m;
      int nap = 0;
      while (x != n || y != 1) {
        d[x][y] = true;
        if (nap == 0) {
          cout << x << " " << y << endl;
          if (!d[x + 1][y])
            x++;
          else {
            y--;
            nap = 1;
          }
        } else {
          cout << x << " " << y << endl;
          if (!d[x - 1][y])
            x--;
          else {
            y--;
            nap = 0;
          }
        }
      }
      cout << x << " " << y << endl;
      cout << 1 << " " << 1;
    }
  }
}
