#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, m;
set<long long> xs = {}, ys = {};
vector<long long> vx, vy;
pair<pair<long long, long long>, long long> hol[1010], ver[1010];
map<long long, int> ma_x, ma_y;
bool blocked[10010][10010][4];
bool visited[10010][10010];
bool isINF;
long long ans = 0;
int MAX_X, MAX_Y;
queue<pair<int, int> > que;
void bfs(int x, int y) {
  que.push(pair<int, int>(x, y));
  if (isINF) return;
  visited[x][y] = true;
  while (!que.empty()) {
    int x = que.front().first, y = que.front().second;
    visited[x][y] = true;
    for (int k = 0; k < 4; k++) {
      int nx = x + dx[k], ny = y + dy[k];
      if (blocked[x][y][k]) continue;
      if (nx >= 0 && ny >= 0)
        if (visited[nx][ny]) continue;
      if (nx < 0 || nx >= MAX_X || ny < 0 || ny >= MAX_Y) {
        isINF = true;
        return;
      }
      que.push(pair<int, int>(nx, ny));
    }
    que.pop();
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    hol[i] = pair<pair<long long, long long>, long long>(
        pair<long long, long long>(a, b), c);
    xs.insert(c);
    ys.insert(a);
    ys.insert(b);
  }
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> c >> a >> b;
    ver[i] = pair<pair<long long, long long>, long long>(
        pair<long long, long long>(a, b), c);
    ys.insert(c);
    xs.insert(a);
    xs.insert(b);
  }
  MAX_X = xs.size() - 1;
  MAX_Y = ys.size() - 1;
  int id = 0;
  for (long long x : xs) {
    vx.push_back(x);
    ma_x[x] = id;
    id++;
  }
  id = 0;
  for (long long y : ys) {
    vy.push_back(y);
    ma_y[y] = id;
    id++;
  }
  for (int i = 0; i < n; i++) {
    int a = ma_y[hol[i].first.first], b = ma_y[hol[i].first.second],
        c = ma_x[hol[i].second];
    for (int y = a; y < b; y++) {
      if (c - 1 >= 0) blocked[c - 1][y][0] = true;
      blocked[c][y][1] = true;
    }
  }
  for (int i = 0; i < m; i++) {
    int a = ma_x[ver[i].first.first], b = ma_x[ver[i].first.second],
        c = ma_y[ver[i].second];
    for (int x = a; x < b; x++) {
      if (c - 1 >= 0) blocked[x][c - 1][2] = true;
      blocked[x][c][3] = true;
    }
  }
  if (*xs.begin() >= 0 || *ys.begin() >= 0) {
    cout << "INF" << endl;
    return;
  }
  auto it_end_x = xs.end(), it_end_y = ys.end();
  it_end_x--;
  it_end_y--;
  if (*it_end_x <= 0 || *it_end_y <= 0) {
    cout << "INF" << endl;
    return;
  }
  int sx = lower_bound(vx.begin(), vx.end(), 0) - vx.begin() - 1;
  int sy = lower_bound(vy.begin(), vy.end(), 0) - vy.begin() - 1;
  bfs(sx, sy);
  if (isINF) {
    cout << "INF" << endl;
    return;
  }
  for (int i = 0; i < MAX_X; i++) {
    for (int j = 0; j < MAX_Y; j++) {
      if (visited[i][j]) {
        ans += (vx[i + 1] - vx[i]) * (vy[j + 1] - vy[j]);
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(50);
  solve();
}
