#include <bits/stdc++.h>
const int N = 3550;
const long long mod = 998244353;
const int INF = 1e+9;
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
map<int, int> l, r;
int d_l[N], d_r[N];
vector<int> la, ra;
vector<pair<int, pair<int, int>>> X, Y;
bool adj_l[N][N], adj_r[N][N], vis[N][N];
int curr1 = 1, curr2 = 1;
long long ans = 0;
bool wea = false;
void llenar() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      adj_l[i][j] = true;
      adj_r[i][j] = true;
    }
  }
}
void dfs(int x, int y) {
  vis[x][y] = true;
  if (wea or (x <= 0) or (x >= (curr1 - 1)) or (y <= 0) or (y >= (curr2 - 1))) {
    wea = true;
    return;
  }
  vis[x][y] = true;
  ans += d_l[x] * d_r[y];
  if (adj_r[y][x] and !vis[x][y - 1]) dfs(x, y - 1);
  if (wea) return;
  if (adj_r[y + 1][x] and !vis[x][y + 1]) dfs(x, y + 1);
  if (wea) return;
  if (adj_l[x][y] and !vis[x - 1][y]) dfs(x - 1, y);
  if (wea) return;
  if (adj_l[x + 1][y] and !vis[x + 1][y]) dfs(x + 1, y);
  if (wea) return;
}
void solve() {
  int n, m;
  cin >> n >> m;
  la.push_back(0);
  ra.push_back(0);
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    X.push_back({c, {a, b}});
    ra.push_back(c);
    la.push_back(a);
    la.push_back(b);
  }
  for (int i = 0; i < m; i++) {
    int d, e, f;
    cin >> d >> e >> f;
    Y.push_back({d, {e, f}});
    ra.push_back(e);
    ra.push_back(f);
    la.push_back(d);
  }
  sort(la.begin(), la.end());
  sort(ra.begin(), ra.end());
  la.erase(unique(la.begin(), la.end()), la.end());
  ra.erase(unique(ra.begin(), ra.end()), ra.end());
  if ((la.size() <= 2) or (ra.size() <= 2)) {
    cout << "INF" << endl;
    return;
  }
  for (auto val : la) l[val] = curr1++;
  for (int i = 0; i < la.size() - 1; i++) {
    d_l[i + 1] = la[i + 1] - la[i];
  }
  for (auto val : ra) r[val] = curr2++;
  for (int i = 0; i < ra.size() - 1; i++) {
    d_r[i + 1] = ra[i + 1] - ra[i];
  }
  llenar();
  for (int i = 0; i < n; i++) {
    int a = X[i].second.first, b = X[i].second.second, c = X[i].first;
    for (int j = l[a]; j < l[b]; j++) adj_r[r[c]][j] = false;
  }
  for (int i = 0; i < m; i++) {
    int d = Y[i].first, e = Y[i].second.first, f = Y[i].second.second;
    for (int j = r[e]; j < r[f]; j++) adj_l[l[d]][j] = false;
  }
  dfs(l[0], r[0]);
  if (wea) {
    cout << "INF" << endl;
    return;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  while (tc--) solve();
  return 0;
}
