#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, m; cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(m), e(m), f(m), ys{-INF, 0, INF}, xs{-INF, 0, INF};
  REP(i, n) {
    cin >> a[i] >> b[i] >> c[i];
    ys.emplace_back(a[i]);
    ys.emplace_back(b[i]);
    xs.emplace_back(c[i]);
  }
  REP(i, m) {
    cin >> d[i] >> e[i] >> f[i];
    ys.emplace_back(d[i]);
    xs.emplace_back(e[i]);
    xs.emplace_back(f[i]);
  }
  sort(ALL(ys));
  ys.erase(unique(ALL(ys)), ys.end());
  sort(ALL(xs));
  xs.erase(unique(ALL(xs)), xs.end());
  // for (int e : ys) cout << e << ' ';
  // cout << '\n';
  // for (int e : xs) cout << e << ' ';
  // cout << '\n';
  REP(i, n) {
    a[i] = lower_bound(ALL(ys), a[i]) - ys.begin();
    b[i] = lower_bound(ALL(ys), b[i]) - ys.begin();
    c[i] = lower_bound(ALL(xs), c[i]) - xs.begin();
  }
  REP(i, m) {
    d[i] = lower_bound(ALL(ys), d[i]) - ys.begin();
    e[i] = lower_bound(ALL(xs), e[i]) - xs.begin();
    f[i] = lower_bound(ALL(xs), f[i]) - xs.begin();
  }
  int Y = ys.size(), X = xs.size();
  vector col(Y, vector(X, 0)), row(Y, vector(X, 0));
  REP(i, n) {
    ++col[a[i]][c[i]];
    --col[b[i]][c[i]];
  }
  REP(j, X) FOR(i, 1, Y) col[i][j] += col[i - 1][j];
  // REP(i, Y) {
  //   REP(j, X) cout << col[i][j];
  //   cout << '\n';
  // }
  REP(i, m) {
    ++row[d[i]][e[i]];
    --row[d[i]][f[i]];
  }
  REP(i, Y) FOR(j, 1, X) row[i][j] += row[i][j - 1];
  // REP(i, Y) {
  //   REP(j, X) cout << row[i][j];
  //   cout << '\n';
  // }
  vector reachable(Y - 1, vector(X - 1, false));
  reachable[lower_bound(ALL(ys), 0) - ys.begin()][lower_bound(ALL(xs), 0) - xs.begin()] = true;
  queue<pair<int, int>> que;
  que.emplace(lower_bound(ALL(ys), 0) - ys.begin(), lower_bound(ALL(xs), 0) - xs.begin());
  while (!que.empty()) {
    auto [i, j] = que.front(); que.pop();
    REP(k, 4) {
      int y = i + dy[k], x = j + dx[k];
      if (y < 0 || Y - 1 <= y || x < 0 || X - 1 <= x || reachable[y][x]) continue;
      if (k == 0) {
        if (row[y][x] == 0) {
          reachable[y][x] = true;
          // cout << i << ' ' << j << " -> " << y << ' ' << x << '\n';
          que.emplace(y, x);
        }
      } else if (k == 1) {
        if (col[i][j] == 0) {
          reachable[y][x] = true;
          // cout << i << ' ' << j << " -> " << y << ' ' << x << '\n';
          que.emplace(y, x);
        }
      } else if (k == 2) {
        if (row[i][j] == 0) {
          reachable[y][x] = true;
          // cout << i << ' ' << j << " -> " << y << ' ' << x << '\n';
          que.emplace(y, x);
        }
      } else {
        if (col[y][x] == 0) {
          reachable[y][x] = true;
          // cout << i << ' ' << j << " -> " << y << ' ' << x << '\n';
          que.emplace(y, x);
        }
      }
    }
  }
  // REP(i, Y - 1) {
  //   REP(j, X - 1) cout << reachable[i][j];
  //   cout << '\n';
  // }
  REP(y, Y - 1) {
    if (reachable[y][0] || reachable[y][X - 2]) {
      cout << "INF\n";
      return 0;
    }
  }
  REP(x, X - 1) {
    if (reachable[0][x] || reachable[Y - 2][x]) {
      cout << "INF\n";
      return 0;
    }
  }
  ll ans = 0;
  REP(y, Y - 1) REP(x, X - 1) {
    if (reachable[y][x]) ans += 1LL * (ys[y + 1] - ys[y]) * (xs[x + 1] - xs[x]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 75632