#include <bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using LL = long long;
using ULL = unsigned long long;
struct Line {
  LL l, r, x;
  bool operator<(const Line& r) const { return x < r.x; }
};
int H, W;
LL X[999], Y[999];
LL Xp[1000], Yp[1000];
Line HL[1000];
Line VL[1000];
int G[2001][2001];
int main() {
  scanf("%d%d", &W, &H);
  for (int i = 0; i < (W); i++)
    scanf("%lld%lld%lld", &VL[i].l, &VL[i].r, &VL[i].x);
  for (int i = 0; i < (H); i++)
    scanf("%lld%lld%lld", &HL[i].x, &HL[i].l, &HL[i].r);
  sort(HL, HL + H);
  sort(VL, VL + W);
  for (int i = 0; i < (H - 1); i++) Y[i] = HL[i + 1].x - HL[i].x;
  for (int i = 0; i < (H); i++) Yp[i] = HL[i].x;
  for (int i = 0; i < (W - 1); i++) X[i] = VL[i + 1].x - VL[i].x;
  for (int i = 0; i < (W); i++) Xp[i] = VL[i].x;
  for (int y = 0; y < (H * 2 + 1); y++)
    for (int x = 0; x < (W * 2 + 1); x++) {
      G[x][y] = 0;
      if (y & x & 1) G[x][y] = -1;
    }
  for (int y = 0; y < (H); y++)
    for (int x = 0; x < (W - 1); x++) {
      if (HL[y].l <= Xp[x] && Xp[x + 1] <= HL[y].r)
        G[x * 2 + 2][y * 2 + 1] = -1;
      if (Xp[x] == Xp[x + 1]) G[x * 2 + 2][y * 2 + 1] = -1;
    }
  for (int x = 0; x < (W); x++)
    for (int y = 0; y < (H - 1); y++) {
      if (VL[x].l <= Yp[y] && Yp[y + 1] <= VL[x].r)
        G[x * 2 + 1][y * 2 + 2] = -1;
      if (Yp[y] == Yp[y + 1]) G[x * 2 + 1][y * 2 + 2] = -1;
    }
  int sx = 0, sy = 0;
  for (int x = 0; x < (W - 1); x++)
    if (Xp[x] <= 0 && 0 <= Xp[x + 1]) sx = x * 2 + 2;
  if (Xp[W - 1] < 0) sx = W * 2;
  for (int y = 0; y < (H - 1); y++)
    if (Yp[y] <= 0 && 0 <= Yp[y + 1]) sy = y * 2 + 2;
  if (Yp[W - 1] < 0) sy = H * 2;
  queue<pair<int, int>> Q;
  Q.push({sx, sy});
  while (Q.size()) {
    int px = Q.front().first;
    int py = Q.front().second;
    Q.pop();
    if (G[px][py]) continue;
    G[px][py] = 1;
    Q.push({px - 1, py});
    Q.push({px + 1, py});
    Q.push({px, py - 1});
    Q.push({px, py + 1});
    if (px == 0 || py == 0 || px == W * 2 || py == H * 2) {
      cout << "INF" << endl;
      return 0;
    }
  }
  LL ans = 0;
  for (int x = 0; x < (W - 1); x++)
    for (int y = 0; y < (H - 1); y++) {
      if (G[x * 2 + 2][y * 2 + 2] == 1) ans += X[x] * Y[y];
    }
  cout << ans << endl;
  return 0;
}
