#include <bits/stdc++.h>
using namespace std;
inline void logger() { std::cout << " [LOGGER] " << endl; }
template <typename A, typename... B>
void logger(const A& a, const B&... b) {
  cout << a << " , ";
  logger(b...);
}
const long long MOD = 1000000007;
const long long MOD9 = 998244353;
const long long INF = MOD * MOD;
const int MAX = 2005 * 2005;
template <class T>
struct coordinate_compression {
  int sz;
  vector<T> arr;
  map<T, int> zip;
  vector<T> unzip;
  coordinate_compression(vector<T> arr) { init(arr); }
  void init(vector<T> arr) {
    sort((arr).begin(), (arr).end());
    arr.erase(unique((arr).begin(), (arr).end()), arr.end());
    for (int(i) = 0; (i) < (arr.size()); (i)++) {
      zip[arr[i]] = i;
      unzip.push_back(arr[i]);
    }
    sz = arr.size();
  }
  int get(T x) { return zip[x]; }
  const T& operator[](int k) const { return unzip[k]; }
};
vector<int> to[MAX], cto[MAX];
bool obs[MAX][4];
long long area[MAX];
bool seen[MAX];
long long X, Y, ans;
int id(int i, int j) { return i * (Y - 1) + j; }
vector<int> around(int _id) {
  int i = _id / (Y - 1), j = _id % (Y - 1);
  vector<int> res(4);
  vector<pair<long long, long long> > d = {
      pair<long long, long long>(0, 1), pair<long long, long long>(0, -1),
      pair<long long, long long>(1, 0), pair<long long, long long>(-1, 0)};
  for (int(k) = 0; (k) < (4); (k)++) {
    if (i + d[k].first < 0 || i + d[k].first >= X - 1 || j + d[k].first < 0 ||
        j + d[k].second >= Y - 1)
      res[k] = -1;
    res[k] = id(i + d[k].first, j + d[k].second);
  }
  return res;
}
bool outside(int _id) {
  if (_id < 0) return true;
  int i = _id / (Y - 1), j = _id % (Y - 1);
  if (i == 0 || i == Y - 2 || j == 0 || j == X - 2) return true;
  return false;
}
bool dfs(int s) {
  ans += area[s];
  auto ar = around(s);
  for (int(k) = 0; (k) < (4); (k)++) {
    if (obs[s][k]) continue;
    if (outside(ar[k])) return true;
    if (seen[ar[k]]) continue;
    seen[ar[k]] = true;
    if (dfs(ar[k])) return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> x = {0, -INF, INF};
  vector<long long> y = {0, -INF, INF};
  vector<tuple<long long, long long, long long> > ver, hor;
  for (int(i) = 0; (i) < (n); (i)++) {
    long long a, b, c;
    cin >> a >> b >> c;
    x.push_back(a);
    x.push_back(b);
    y.push_back(c);
    ver.push_back(tuple<long long, long long, long long>(a, b, c));
  }
  for (int(i) = 0; (i) < (m); (i)++) {
    long long a, b, c;
    cin >> a >> b >> c;
    x.push_back(a);
    y.push_back(b);
    y.push_back(c);
    hor.push_back(tuple<long long, long long, long long>(a, b, c));
  }
  coordinate_compression<long long> cx(x), cy(y);
  X = cx.sz, Y = cy.sz;
  for (int(i) = 0; (i) < (n); (i)++) {
    int a = cx.get(get<0>(ver[i])), b = cx.get(get<1>(ver[i])),
        c = cy.get(get<2>(ver[i]));
    for (int(j) = (a); (j) < (b); (j)++) {
      int u = id(j, c - 1), v = id(j, c);
      obs[u][0] = true;
      obs[v][1] = true;
    }
  }
  for (int(i) = 0; (i) < (m); (i)++) {
    int d = cx.get(get<0>(hor[i])), e = cy.get(get<1>(hor[i])),
        f = cy.get(get<2>(hor[i]));
    for (int(j) = (e); (j) < (f); (j)++) {
      int u = id(d - 1, j), v = id(d, j);
      obs[u][2] = true;
      obs[v][3] = true;
    }
  }
  for (int(i) = 0; (i) < (X - 1); (i)++)
    for (int(j) = 0; (j) < (Y - 1); (j)++)
      area[id(i, j)] = (cx[i + 1] - cx[i]) * (cy[j + 1] - cy[j]);
  ans = 0;
  int z = id(cx.get(0), cy.get(0));
  seen[z] = true;
  bool res = dfs(z);
  if (res)
    cout << ("INF") << endl;
  else
    cout << (ans) << endl;
}
