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