#include <bits/stdc++.h>
struct block_t {
  std::pair<int, int> xbound, ybound;
  block_t() {}
  block_t(const std::pair<int, int>& x, const std::pair<int, int>& y)
      : xbound(x), ybound(y) {}
  bool is_through(const std::pair<int, int>& pos,
                  const std::pair<int, int>& dir) const {
    double tx = pos.first + 0.5 * (1 + dir.first);
    double ty = pos.second + 0.5 * (1 + dir.second);
    return !((double(xbound.first) <= tx) && (tx <= double(xbound.second)) &&
             (double(ybound.first) <= ty && ty <= double(ybound.second)));
  }
};
int main() {
  size_t n, m;
  std::cin >> n >> m;
  using pos_t = std::pair<int, int>;
  std::vector<block_t> blocks;
  bool xu = false, xl = false, yu = false, yl = false;
  for (size_t i = 0; i < n; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    if (c > 0) yu = true;
    if (c < 0) yl = true;
    blocks.push_back(block_t({a, b}, {c, c}));
  }
  for (size_t i = 0; i < m; i++) {
    int d, e, f;
    std::cin >> d >> e >> f;
    if (d > 0) xu = true;
    if (d < 0) xl = true;
    blocks.push_back(block_t({d, d}, {e, f}));
  }
  std::vector<std::pair<int, int>> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  int area = 0;
  if (!(xu && xl && yu && yl)) {
    std::cout << "INF\n";
  } else {
    std::stack<std::pair<int, int>> search;
    search.push({0, 0});
    std::map<std::pair<int, int>, bool> flag;
    flag[{0, 0}] = true;
    while (!search.empty()) {
      auto searching = search.top();
      area++;
      search.pop();
      for (auto&& dir : dirs) {
        std::pair<int, int> next = {searching.first + dir.first,
                                    searching.second + dir.second};
        if (!flag[next] && std::all_of(blocks.begin(), blocks.end(),
                                       [&searching, &dir](const block_t& b) {
                                         return b.is_through(searching, dir);
                                       })) {
          flag[next] = true;
          search.push(next);
        }
      }
    }
    std::cout << area << "\n";
  }
  return 0;
}
