#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int n, m;
int a, b, c, mp[3005][3005];
vector<int> x, y;
map<int, int> rx, ry;
tuple<int, int, int> d[1005], e[1005];
void zip(vector<int> &v, map<int, int> &mp) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int t = 0;
  for (int u : v) mp[u] = t++;
}
stack<P> st;
long long ans;
bool inf = false;
int main() {
  scanf("%d", &n, &m);
  x.push_back(0);
  y.push_back(0);
  x.push_back((int)1e9 + 5);
  x.push_back((int)-1e9 - 5);
  y.push_back((int)1e9 + 5);
  y.push_back((int)-1e9 - 5);
  for (int i = 0; i < (n); i++) {
    scanf("%d%d%d", &a, &b, &c);
    d[i] = {a, b, c};
    x.push_back(a);
    x.push_back(b);
    y.push_back(c);
  }
  for (int i = 0; i < (m); i++) {
    scanf("%d%d%d", &a, &b, &c);
    e[i] = {a, b, c};
    x.push_back(a);
    y.push_back(b);
    y.push_back(c);
  }
  zip(x, rx);
  zip(y, ry);
  for (int i = 0; i < (n); i++) {
    tie(a, b, c) = d[i];
    a = rx[a];
    b = rx[b];
    c = ry[c];
    for (int i = a; i < b; i++) {
      mp[i][c] ^= 1;
      mp[i][c - 1] ^= 4;
    }
  }
  for (int i = 0; i < (m); i++) {
    tie(a, b, c) = e[i];
    a = rx[a];
    b = ry[b];
    c = ry[c];
    for (int j = b; j < c; j++) {
      mp[a][j] ^= 2;
      mp[a - 1][j] ^= 8;
    }
  }
  st.push({rx[0], ry[0]});
  while (!st.empty()) {
    tie(a, b) = st.top();
    st.pop();
    ans += (long long)(x[a + 1] - x[a]) * (y[b + 1] - y[b]);
    if (mp[a][b] & 1) {
      if (b == 0)
        inf = true;
      else
        st.push({a, b - 1});
    }
    if (mp[a][b] >> 1 & 1) {
      if (a == 0)
        inf = true;
      else
        st.push({a - 1, b});
    }
    if (mp[a][b] >> 2 & 1) {
      if (b == ry[(int)1e9 + 5])
        inf = true;
      else
        st.push({a, b + 1});
    }
    if (mp[a][b] >> 3 & 1) {
      if (a == rx[(int)1e9 + 5])
        inf = true;
      else
        st.push({a + 1, b});
    }
  }
  if (!inf)
    printf("%lld", ans);
  else
    puts("INF");
}
