#include <bits/stdc++.h>
struct Line {
  int a, b, c;
};
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<Line> h(n), v(m);
  for (int i = 0; i < n; i++) {
    std::cin >> h[i].b >> h[i].c >> h[i].a;
    if (h[i].b > h[i].c) std::swap(h[i].b, h[i].c);
    h[i].a *= 2;
    h[i].b *= 2;
    h[i].c *= 2;
  }
  for (int i = 0; i < m; i++) {
    std::cin >> v[i].a >> v[i].b >> v[i].c;
    if (v[i].b > v[i].c) std::swap(v[i].b, v[i].c);
    v[i].a *= 2;
    v[i].b *= 2;
    v[i].c *= 2;
  }
  std::map<int, int> lmp, rmp;
  for (int i = 0; i < n; i++) {
    for (int t = -1; t <= 1; t++) {
      lmp[h[i].b + t];
      lmp[h[i].c + t];
      rmp[h[i].a + t];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int t = -1; t <= 1; t++) {
      rmp[v[i].b + t];
      rmp[v[i].c + t];
      lmp[v[i].a + t];
    }
  }
  for (int t = -1; t <= 1; t++) {
    lmp[t];
    rmp[t];
  }
  int cntl = 0, cntr = 0;
  for (auto &p : lmp) p.second = cntl++;
  for (auto &p : rmp) p.second = cntr++;
  std::vector<std::vector<int>> tab(cntl, std::vector<int>(cntr));
  for (int i = 0; i < n; i++) {
    int u = rmp[h[i].a];
    for (int j = lmp[h[i].b]; j <= lmp[h[i].c]; j++) {
      tab[j][u] = -1;
    }
  }
  for (int i = 0; i < m; i++) {
    int u = lmp[v[i].a];
    for (int j = rmp[v[i].b]; j <= rmp[v[i].c]; j++) {
      tab[u][j] = -1;
    }
  }
  std::vector<int> d = {1, 0, -1, 0, 1};
  std::deque<std::pair<int, int>> que;
  que.emplace_back(lmp[0], rmp[0]);
  tab[lmp[0]][rmp[0]] = 1;
  while (!que.empty()) {
    auto p = que.front();
    que.pop_front();
    for (int i = 0; i < 4; i++) {
      int x = p.first + d[i];
      int y = p.second + d[i + 1];
      if (!(0 <= x && x < cntl)) continue;
      if (!(0 <= y && y < cntr)) continue;
      if (tab[x][y] != 0) continue;
      tab[x][y] = 1;
      que.emplace_back(x, y);
    }
  }
  for (int i = 0; i < cntl; i++) {
    if (tab[i][0] == 1 || tab[i][cntr - 1] == 1) {
      std::cout << "INF" << std::endl;
      return 0;
    }
  }
  for (int i = 0; i < cntr; i++) {
    if (tab[0][i] == 1 || tab[cntl - 1][i] == 1) {
      std::cout << "INF" << std::endl;
      return 0;
    }
  }
  std::vector<std::vector<int>> valp(cntl, std::vector<int>(cntr)),
      valq(cntl, std::vector<int>(cntr));
  for (auto &p : lmp)
    for (auto &q : rmp) {
      valp[p.second][q.second] = p.first;
      valq[p.second][q.second] = q.first;
    }
  long long ans = 0;
  for (int i = 1; i < cntl - 1; i++) {
    for (int j = 1; j < cntr - 1; j++) {
      if (valp[i][j] % 2 == 0 || valq[i][j] % 2 == 0) continue;
      if (tab[i][j] != 1) continue;
      ans += ((long long)valp[i + 1][j] - valp[i - 1][j]) *
             ((long long)valq[i][j + 1] - valq[i][j - 1]) / 4;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
