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