#include <bits/stdc++.h>
using namespace std;
int n, m;
void print_hor(int x, int y) {
  bool d = true;
  int cur_x = x, cur_y = y;
  while (cur_x != n + 1) {
    if (d)
      for (int i = y; i <= m; i++) printf("%i %i\n", cur_x, i);
    else
      for (int i = m; i >= y; i--) printf("%i %i\n", cur_x, i);
    cur_x++;
    d = !d;
  }
}
void print_vert(int x, int y) {
  bool d = true;
  int cur_y = y;
  while (cur_y != m + 1) {
    if (d)
      for (int i = x; i <= n; i++) printf("%i %i\n", i, cur_y);
    else
      for (int i = n; i >= x; i--) printf("%i %i\n", i, cur_y);
    cur_y++;
    d = !d;
  }
}
int main() {
  scanf("%i%i", &n, &m);
  if (n == 1) {
    if (m != 2)
      printf("1\n1 %i 1 1\n", m);
    else
      printf("0\n");
    for (int i = 1; i <= m; i++) printf("1 %i\n", i);
    printf("1 1\n");
    return 0;
  }
  if (m == 1) {
    if (n != 2)
      printf("1\n%i 1 1 1\n", n);
    else
      printf("0\n");
    for (int i = 1; i <= n; i++) printf("%i 1\n", i);
    printf("1 1\n");
    return 0;
  }
  if (n % 2 == 0) {
    printf("0\n1 1\n");
    print_hor(1, 2);
    for (int i = n; i >= 1; i--) printf("%i 1\n", i);
    return 0;
  }
  if (m % 2 == 0) {
    printf("0\n1 1\n");
    print_vert(2, 1);
    for (int i = m; i >= 1; i--) printf("1 %i\n", i);
    return 0;
  }
  printf("1\n%i %i 1 1\n", n, m);
  print_vert(1, 1);
  printf("1 1\n");
  return 0;
}
