#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 100;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
int grid[6100][6100] = {{0}};
bool vis[6100][6100] = {{0}};
map<int, int> M;
map<int, int> VAL;
bool isINF = 0;
long long ans = 1;
void dfs(int x, int y) {
  if (x == 0 || y == 0 || x > M.size() || y > M.size()) {
    isINF = 1;
    return;
  }
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    if (!vis[x + dx[i]][y + dy[i]] && (grid[x][y] & (1 << i)) == 0) {
      ans += abs(VAL[x] - VAL[x + dx[i]]);
      ans += abs(VAL[y] - VAL[y + dy[i]]);
      dfs(x + dx[i], y + dy[i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  M.insert({0, -1});
  vector<int> vx1(n);
  vector<int> vx2(n);
  vector<int> vy(n);
  for (int i = 0; i < n; i++) {
    cin >> vx1[i] >> vx2[i] >> vy[i];
    if (vx1[i] > vx2[i]) {
      swap(vx1[i], vx2[i]);
    }
    M.insert({vx1[i], -1});
    M.insert({vx2[i], -1});
    M.insert({vy[i], -1});
  }
  vector<int> hx(m);
  vector<int> hy1(m);
  vector<int> hy2(m);
  for (int i = 0; i < m; i++) {
    cin >> hx[i] >> hy1[i] >> hy2[i];
    if (hy1[i] > hy2[i]) {
      swap(vx1[i], vx2[i]);
    }
    M.insert({hx[i], -1});
    M.insert({hy1[i], -1});
    M.insert({hy2[i], -1});
  }
  M[-INF] = 0;
  int id = 0;
  for (auto &it : M) {
    it.second = id;
    VAL[id] = it.first;
    id++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = M[vx1[i]]; j < M[vx2[i]]; j++) {
      grid[M[vy[i]] - 1][j] |= 4;
      grid[M[vy[i]]][j] |= 1;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = M[hy1[i]]; j < M[hy2[i]]; j++) {
      grid[j][M[hx[i]] - 1] |= 2;
      grid[j][M[hx[i]]] |= 8;
    }
  }
  dfs(M[0], M[0]);
  if (isINF) {
    cout << "INF" << '\n';
  } else {
    cout << ans << '\n';
  }
  return 0;
}
