#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
int flag0[3020][3020];
int flag1[3020][3020];
int vis[3020][3020];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
  map<int, int> mp0, mp1;
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    mp0[a[i]] = 0;
    mp0[b[i]] = 0;
    mp1[c[i]] = 0;
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &d[i], &e[i], &f[i]);
    mp0[d[i]] = 0;
    mp1[e[i]] = 0;
    mp1[f[i]] = 0;
  }
  vector<int> diff0, diff1;
  {
    int cnt = 0;
    auto it = mp0.begin();
    int prev = 0;
    for (; it != mp0.end(); ++it) {
      int curr = it->first;
      if (cnt > 0) diff0.push_back(curr - prev);
      it->second = cnt;
      cnt++;
      prev = curr;
    }
  }
  {
    int cnt = 0;
    auto it = mp1.begin();
    int prev = 0;
    for (; it != mp1.end(); ++it) {
      int curr = it->first;
      if (cnt > 0) diff1.push_back(curr - prev);
      it->second = cnt;
      cnt++;
      prev = curr;
    }
  }
  for (i = 0; i < n; i++) {
    a[i] = mp0[a[i]];
    b[i] = mp0[b[i]];
    c[i] = mp1[c[i]];
    int k;
    for (k = a[i]; k < b[i]; k++) {
      flag1[k][c[i]] = 1;
    }
  }
  for (i = 0; i < m; i++) {
    d[i] = mp0[d[i]];
    e[i] = mp1[e[i]];
    f[i] = mp1[f[i]];
    int k;
    for (k = e[i]; k < f[i]; k++) {
      flag0[d[i]][k] = 1;
    }
  }
  long long ans = 0;
  queue<int> que;
  int sx = mp0[0], sy = mp1[0];
  que.push(((sx)*3010 + (sy)));
  vis[sx][sy] = 1;
  ans += (long long)diff0[sx] * diff1[sy];
  while (!que.empty()) {
    int curr = que.front();
    que.pop();
    int x = curr / 3010;
    int y = curr % 3010;
    int k;
    for (k = 0; k < 4; k++) {
      int x2 = x + dx[k], y2 = y + dy[k];
      if (k == 0) {
        if (flag0[x + 1][y]) continue;
      } else if (k == 1) {
        if (flag0[x][y]) continue;
      } else if (k == 2) {
        if (flag1[x][y + 1]) continue;
      } else {
        if (flag1[x][y]) continue;
      }
      if (x2 < 0 || x2 >= 3010 || y2 < 0 || y2 >= 3010) {
        printf("INF\n");
        return;
      }
      if (vis[x2][y2] == 0) {
        que.push(((x2)*3010 + (y2)));
        vis[x2][y2] = 1;
        ans += (long long)diff0[x2] * diff1[y2];
      }
    }
  }
  printf("%lld\n", ans);
  return;
}
int main(int argc, char* argv[]) {
  solve();
  return 0;
}
