#include <bits/stdc++.h>
using namespace std;
int get(vector<int> &all) {
  auto it = upper_bound(all.begin(), all.end(), 0);
  return it - all.begin() - 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<array<int, 3> > ver(n), hor(m);
  vector<int> allx, ally;
  for (int i = 0; i < n; ++i) {
    cin >> ver[i][0] >> ver[i][1] >> ver[i][2];
    allx.push_back(ver[i][0]);
    allx.push_back(ver[i][1]);
    ally.push_back(ver[i][2]);
  }
  for (int i = 0; i < m; ++i) {
    cin >> hor[i][0] >> hor[i][1] >> hor[i][2];
    allx.push_back(hor[i][0]);
    ally.push_back(hor[i][1]);
    ally.push_back(hor[i][2]);
  }
  allx.push_back(-2e9);
  allx.push_back(2e9);
  ally.push_back(-2e9);
  ally.push_back(2e9);
  sort(allx.begin(), allx.end());
  allx.erase(unique(allx.begin(), allx.end()), allx.end());
  sort(ally.begin(), ally.end());
  ally.erase(unique(ally.begin(), ally.end()), ally.end());
  map<int, int> tox, toy;
  vector<int> revx(int(allx.size())), revy(int(ally.size()));
  for (int i = 0; i < int(allx.size()); ++i) {
    tox[allx[i]] = i;
    revx[i] = allx[i];
  }
  for (int i = 0; i < int(ally.size()); ++i) {
    toy[ally[i]] = i;
    revy[i] = ally[i];
  }
  int len = max(int(allx.size()), int(ally.size())) + 5;
  vector<vector<bool> > up(len, vector<bool>(len, true));
  vector<vector<bool> > dw(len, vector<bool>(len, true));
  vector<vector<bool> > lp(len, vector<bool>(len, true));
  vector<vector<bool> > rp(len, vector<bool>(len, true));
  for (int i = 0; i < n; ++i) {
    int a = tox[ver[i][0]];
    int b = tox[ver[i][1]];
    int c = toy[ver[i][2]];
    for (int pair<int, int> = a; pair<int, int> < b; ++pair<int, int>) {
      lp[pair<int, int>][c] = false;
      rp[pair<int, int>][c - 1] = false;
    }
  }
  for (int i = 0; i < m; ++i) {
    int c = tox[hor[i][0]];
    int a = toy[hor[i][1]];
    int b = toy[hor[i][2]];
    for (int pair<int, int> = a; pair<int, int> < b; ++pair<int, int>) {
      dw[c - 1][pair<int, int>] = false;
      up[c][pair<int, int>] = false;
    }
  }
  int px = get(allx);
  int py = get(ally);
  vector<vector<bool> > vist(len, vector<bool>(len, false));
  queue<pair<int, int> > q;
  q.push(pair<int, int>(px, py));
  vist[px][py] = true;
  auto valid = [&](int x, int y) {
    return x >= 0 && x < len && y >= 0 && y < len && !vist[x][y];
  };
  while (int(q.size())) {
    pair<int, int> par = q.front();
    q.pop();
    int x = par.first, y = par.second;
    if (up[x][y]) {
      int nx = x - 1, ny = y;
      if (valid(nx, ny)) {
        vist[nx][ny] = true;
        q.push(pair<int, int>(nx, ny));
      }
    }
    if (dw[x][y]) {
      int nx = x + 1, ny = y;
      if (valid(nx, ny)) {
        vist[nx][ny] = true;
        q.push(pair<int, int>(nx, ny));
      }
    }
    if (lp[x][y]) {
      int nx = x, ny = y - 1;
      if (valid(nx, ny)) {
        vist[nx][ny] = true;
        q.push(pair<int, int>(nx, ny));
      }
    }
    if (rp[x][y]) {
      int nx = x, ny = y + 1;
      if (valid(nx, ny)) {
        vist[nx][ny] = true;
        q.push(pair<int, int>(nx, ny));
      }
    }
  }
  if (vist[0][0]) {
    cout << "INF" << endl;
    exit(0);
  }
  long long ans = 0;
  for (int i = 0; i < len; ++i) {
    for (int j = 0; j < len; ++j) {
      if (vist[i][j]) {
        ans += (allx[i + 1] - allx[i]) * (ally[j + 1] - ally[j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
