#include <bits/stdc++.h>
using namespace std;
map<long long, vector<pair<long long, long long> > > u1;
map<long long, vector<pair<long long, long long> > > u2;
vector<long long> keys1;
vector<long long> keys2;
bool check1(long long x, long long y, long long z) {
  vector<pair<long long, long long> > v = u1[keys2[y]];
  for (long long i = 0; i < v.size(); ++i) {
    if (v[i].first <= keys1[x - 1] && v[i].second >= keys1[x]) {
      return false;
    }
  }
  return true;
}
bool check2(long long x, long long y, long long z) {
  vector<pair<long long, long long> > v = u2[keys1[y]];
  for (long long i = 0; i < v.size(); ++i) {
    if (v[i].first <= keys2[x - 1] && v[i].second >= keys2[x]) {
      return false;
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  pair<long long, pair<long long, long long> > a[n];
  pair<long long, pair<long long, long long> > b[m];
  set<long long> o1;
  set<long long> o2;
  for (long long i = 0; i < n; ++i) {
    long long x, y, z;
    cin >> x >> y >> z;
    a[i] = {z, {x, y}};
    if (!o1.count(z)) {
      vector<pair<long long, long long> > v;
      v.push_back({x, y});
      u1[z] = v;
      o1.insert(z);
      keys1.push_back(z);
    } else {
      u1[z].push_back({x, y});
    }
  }
  for (long long i = 0; i < m; ++i) {
    long long x, y, z;
    cin >> z >> x >> y;
    b[i] = {z, {x, y}};
    if (!o2.count(z)) {
      vector<pair<long long, long long> > v;
      v.push_back({x, y});
      u2[z] = v;
      o2.insert(z);
      keys2.push_back(z);
    } else {
      u2[z].push_back({x, y});
    }
  }
  sort(keys1.begin(), keys1.end());
  sort(keys2.begin(), keys2.end());
  long long n1 = keys1.size();
  long long m1 = keys2.size();
  long long s[n1 + 1][m1 + 1];
  for (long long i = 0; i <= n1; ++i) {
    for (long long j = 0; j <= m1; ++j) {
      if (i == 0 || i == n1) {
        s[i][j] = (-1);
        continue;
      }
      if (j == 0 || j == m1) {
        s[i][j] = (-1);
        continue;
      }
      s[i][j] = (keys1[i] - keys1[i - 1]) * (keys2[j] - keys2[j - 1]);
    }
  }
  long long x1 = upper_bound(keys1.begin(), keys1.end(), 0) - keys1.begin();
  long long y1 = upper_bound(keys2.begin(), keys2.end(), 0) - keys2.begin();
  deque<pair<long long, long long> > q;
  vector<pair<long long, long long> > v;
  bool used[n + 1][m + 1];
  q.push_back({x1, y1});
  v.push_back({x1, y1});
  if (keys1[x1 - 1] == 0) {
    q.push_back({x1 - 1, y1});
    v.push_back({x1 - 1, y1});
  }
  if (keys2[y1 - 1] == 0) {
    q.push_back({x1, y1 - 1});
    v.push_back({x1, y1 - 1});
  }
  if (keys1[x1 - 1] == 0 && keys2[y1 - 1] == 0) {
    q.push_back({x1 - 1, y1 - 1});
    v.push_back({x1 - 1, y1 - 1});
  }
  for (long long i = 0; i <= n; ++i) {
    for (long long j = 0; j <= m; ++j) {
      used[i][j] = false;
    }
  }
  for (long long i = 0; i < v.size(); ++i) {
    used[v[i].first][v[i].second] = true;
  }
  long long ans = 0;
  while (!q.empty()) {
    deque<pair<long long, long long> > q1;
    while (!q.empty()) {
      pair<long long, long long> o = q.front();
      q.pop_front();
      long long x = o.first;
      long long y = o.second;
      ans += s[x][y];
      if (s[x][y] == (-1)) {
        cout << "INF";
        return 0;
      }
      if (!used[x][y - 1] && check1(x, y - 1, y)) {
        q1.push_back({x, y - 1});
        used[x][y - 1] = true;
      }
      if (!used[x][y + 1] && check1(x, y, y + 1)) {
        q1.push_back({x, y + 1});
        used[x][y + 1] = true;
      }
      if (!used[x - 1][y] && check2(y, x - 1, x)) {
        q1.push_back({x - 1, y});
        used[x - 1][y] = true;
      }
      if (!used[x + 1][y] && check2(y, x, x + 1)) {
        q1.push_back({y, x + 1});
        used[x + 1][y] = true;
      }
    }
    q = q1;
  }
  cout << ans;
  return 0;
}
