#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long mod2 = 998244353;
long long mod3 = 1000003;
long long mod4 = 998244853;
long long mod5 = 1000000009;
long long inf = 1LL << 62;
int iinf = 1 << 30;
double pi = 3.141592653589793238462643383279L;
double eps = 1e-14;
int dh[4] = {1, -1, 0, 0};
int dw[4] = {0, 0, 1, -1};
int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long c = gcd(a, b);
  return a * b / c;
}
long long Pow(long long n, long long k) {
  long long ret = 1;
  long long now = n;
  while (k > 0) {
    if (k & 1) ret *= now;
    now *= now;
    k /= 2;
  }
  return ret;
}
long long beki(long long n, long long k, long long md) {
  long long ret = 1;
  long long now = n;
  now %= md;
  while (k > 0) {
    if (k % 2 == 1) {
      ret *= now;
      ret %= md;
    }
    now *= now;
    now %= md;
    k /= 2;
  }
  return ret;
}
long long gyaku(long long n, long long md) { return beki(n, md - 2, md); }
long long poc(long long n) {
  long long ret = 0;
  long long u = n;
  while (u > 0) {
    ret += u % 2;
    u /= 2;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> v, w;
  long long a[n], b[n], c[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    v.push_back(c[i]);
    w.push_back(a[i]);
    w.push_back(b[i]);
  }
  long long d[m], e[m], f[m];
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    v.push_back(e[i]);
    v.push_back(f[i]);
    w.push_back(d[i]);
  }
  v.push_back(0);
  w.push_back(0);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  sort(w.begin(), w.end());
  w.erase(unique(w.begin(), w.end()), w.end());
  map<long long, long long> mpv, mpw;
  for (int i = 0; i < v.size(); i++) mpv[v[i]] = i + 1;
  for (int i = 0; i < w.size(); i++) mpw[w[i]] = i + 1;
  long long sum[v.size() + 2][w.size() + 2], sum2[v.size() + 2][w.size() + 2];
  memset(sum, 0, sizeof sum);
  memset(sum2, 0, sizeof sum2);
  for (int i = 0; i < n; i++) {
    a[i] = mpw[a[i]];
    b[i] = mpw[b[i]];
    c[i] = mpv[c[i]];
    sum[c[i]][a[i]]++;
    sum[c[i]][b[i]]--;
  }
  for (int i = 0; i < m; i++) {
    d[i] = mpw[d[i]];
    e[i] = mpv[e[i]];
    f[i] = mpv[f[i]];
    sum2[e[i]][d[i]]++;
    sum2[f[i]][d[i]]--;
  }
  for (int i = 0; i < v.size() + 2; i++) {
    for (int j = 1; j < w.size() + 2; j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }
  for (int i = 0; i < w.size() + 2; i++) {
    for (int j = 1; j < v.size() + 2; j++) {
      sum2[j][i] += sum2[j - 1][i];
    }
  }
  queue<pair<long long, long long> > q;
  long long sx = mpv[0], sy = mpw[0];
  q.push({sx, sy});
  bool used[v.size() + 1][w.size() + 1];
  memset(used, false, sizeof used);
  used[sx][sy] = true;
  long long ans = 1;
  while (q.size() > 0) {
    pair<long long, long long> p = q.front();
    q.pop();
    long long nx = p.first, ny = p.second;
    if (nx == v.size() + 2 || nx == 0 || ny == w.size() + 2 || ny == 0) {
      cout << "INF" << endl;
      return 0;
    }
    long long nnx = nx + 1, nny = ny;
    if (used[nnx][nny] == false && sum[nnx][nny] == 0) {
      used[nnx][nny] = true;
      q.push({nnx, nny});
      ans += v[nnx - 1] - v[nx - 1];
    }
    nnx = nx - 1, nny = ny;
    if (used[nnx][nny] == false && sum[nx][nny] == 0) {
      used[nnx][nny] = true;
      q.push({nnx, nny});
      ans += v[nx - 1] - v[nnx - 1];
    }
    nnx = nx, nny = ny + 1;
    if (used[nnx][nny] == false && sum2[nnx][nny] == 0) {
      used[nnx][nny] = true;
      q.push({nnx, nny});
      ans += w[nny - 1] - w[ny - 1];
    }
    nnx = nx, nny = ny - 1;
    if (used[nnx][nny] == false && sum2[nnx][ny] == 0) {
      used[nnx][nny] = true;
      q.push({nnx, nny});
      ans += w[ny - 1] - w[nny - 1];
    }
  }
  cout << ans << endl;
}
