#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> field[4020][4020];
bool ok[4020][4020];
bool visited[4020][4020];
long long int len_x[4040];
long long int len_y[4040];
set<long long int> x;
set<long long int> y;
map<long long int, long long int> za_x;
map<long long int, long long int> za_y;
pair<long long int, pair<long long int, long long int> > tatesen[1010];
pair<long long int, pair<long long int, long long int> > yokosen[1010];
long long int n, m;
long long int dy[] = {-1, 1, 0, 0};
long long int dx[] = {0, 0, -1, 1};
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    cin >> yokosen[i].second.first >> yokosen[i].second.second >>
        yokosen[i].first;
    x.insert(yokosen[i].second.first);
    x.insert(yokosen[i].second.second);
    y.insert(yokosen[i].first);
  }
  for (long long int i = 0; i < ((long long int)(m)); i++) {
    cin >> tatesen[i].first >> tatesen[i].second.first >>
        tatesen[i].second.second;
    x.insert(tatesen[i].first);
    y.insert(tatesen[i].second.first);
    y.insert(tatesen[i].second.second);
  }
  {
    long long int cnt = 0;
    long long int prev = -(1ll << (long long int)(60));
    for (auto v : x) {
      za_x[v] = cnt * 2 + 1;
      len_x[cnt * 2 + 1] = 0;
      if (prev != -(1ll << (long long int)(60))) {
        len_x[cnt * 2] = v - prev;
      }
      cnt++;
      prev = v;
    }
    len_x[((long long int)(x).size()) * 2] = -1;
    len_x[0] = -1;
  }
  {
    long long int cnt = 0;
    long long int prev = -(1ll << (long long int)(60));
    for (auto v : y) {
      za_y[v] = cnt * 2 + 1;
      len_y[cnt * 2 + 1] = 0;
      if (prev != -(1ll << (long long int)(60))) {
        len_y[cnt * 2] = v - prev;
      }
      cnt++;
      prev = v;
    }
    len_y[((long long int)(x).size()) * 2] = -1;
    len_y[0] = -1;
  }
  {
    for (long long int i = 0; i < ((long long int)(4000)); i++) {
      for (long long int j = 0; j < ((long long int)(4000)); j++) {
        ok[i][j] = true;
      }
    }
    for (long long int i = 0; i < ((long long int)(n)); i++) {
      for (long long int xx = (long long int)(za_x[yokosen[i].second.first]);
           xx < ((long long int)(za_x[yokosen[i].second.second] + 1)); xx++) {
        ok[za_y[yokosen[i].first]][xx] = false;
      }
    }
    for (long long int i = 0; i < ((long long int)(m)); i++) {
      for (long long int yy = (long long int)(za_y[tatesen[i].second.first]);
           yy < ((long long int)(za_y[tatesen[i].second.second] + 1)); yy++) {
        ok[yy][za_x[tatesen[i].first]] = false;
      }
    }
  }
  pair<long long int, long long int> s;
  {
    long long int cnt = 0;
    for (auto v : x) {
      if (v >= 0) {
        s.second = cnt * 2;
        break;
      }
      cnt++;
    }
    cnt = 0;
    for (auto v : y) {
      if (v >= 0) {
        s.first = cnt * 2;
        break;
      }
      cnt++;
    }
  }
  queue<pair<long long int, long long int> > q;
  q.push(s);
  long long int res = 0;
  while (!q.empty()) {
    pair<long long int, long long int> now = q.front();
    q.pop();
    if (visited[now.first][now.second]) {
      continue;
    }
    visited[now.first][now.second] = true;
    if (min(len_y[now.first], len_x[now.second]) < 0) {
      puts("INF");
      return 0;
    }
    res += len_y[now.first] * len_x[now.second];
    for (long long int i = 0; i < ((long long int)(4)); i++) {
      pair<long long int, long long int> next = {now.first + dy[i],
                                                 now.second + dx[i]};
      if (!ok[next.first][next.second]) {
        continue;
      }
      q.push(next);
    }
  }
  cout << res << endl;
  return 0;
}
