#include <bits/stdc++.h>
using namespace std;
template <typename T>
void unique(T &c) {
  c.erase(std::unique(c.begin(), c.end()), c.end());
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 != vec.size()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    os << "(" << itr->first << ", " << itr->second << ")";
    auto titr = itr;
    if (++titr != mp.end()) os << " ";
  }
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) {
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    os << "(" << itr->first << ", " << itr->second << ")";
    auto titr = itr;
    if (++titr != mp.end()) os << " ";
  }
  return os;
}
using ll = long long int;
using P = pair<int, int>;
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
struct fast_io {
  fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
  }
} fast_io_;
bool v[6010][6010];
int col[6010][6010];
int X = 0, Y = 0;
void dfs(int i, int j, int c) {
  queue<P> q;
  q.push(make_pair(i, j));
  col[i][j] = c;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    for (int k = (0); k < (4); ++k) {
      int nx = p.first + dx[k], ny = p.second + dy[k];
      if (nx >= 0 && nx < X && ny >= 0 && ny < Y) {
        if (v[nx][ny]) continue;
        if (col[nx][ny]) continue;
        col[nx][ny] = c;
        q.push(make_pair(nx, ny));
      }
    }
  }
}
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n), c(n), d(m), e(m), f(m);
  for (int i = (0); i < (n); ++i) cin >> a[i] >> b[i] >> c[i];
  for (int i = (0); i < (m); ++i) cin >> d[i] >> e[i] >> f[i];
  for (int i = (0); i < (n); ++i) {
    a[i] *= 2;
    b[i] *= 2;
    c[i] *= 2;
  }
  for (int i = (0); i < (m); ++i) {
    d[i] *= 2;
    e[i] *= 2;
    f[i] *= 2;
  }
  vector<ll> x, y;
  x.emplace_back(0);
  y.emplace_back(0);
  for (int i = (0); i < (n); ++i) {
    x.emplace_back(a[i] - 1);
    x.emplace_back(a[i]);
    x.emplace_back(a[i] + 1);
    x.emplace_back(b[i] - 1);
    x.emplace_back(b[i]);
    x.emplace_back(b[i] + 1);
    y.emplace_back(c[i] - 1);
    y.emplace_back(c[i]);
    y.emplace_back(c[i] + 1);
  }
  for (int i = (0); i < (m); ++i) {
    x.emplace_back(d[i] - 1);
    x.emplace_back(d[i]);
    x.emplace_back(d[i] + 1);
    y.emplace_back(e[i] - 1);
    y.emplace_back(e[i]);
    y.emplace_back(e[i] + 1);
    y.emplace_back(f[i] - 1);
    y.emplace_back(f[i]);
    y.emplace_back(f[i] + 1);
  }
  sort((x).begin(), (x).end());
  unique(x);
  map<ll, int> mpx;
  for (int i = (0); i < (((int)(x).size())); ++i) mpx[x[i]] = i;
  sort((y).begin(), (y).end());
  unique(y);
  map<ll, int> mpy;
  for (int i = (0); i < (((int)(y).size())); ++i) mpy[y[i]] = i;
  for (int i = (0); i < (n); ++i) {
    int yc = mpy[c[i]];
    int xs = mpx[a[i]], xt = mpx[b[i]];
    for (int j = xs; j <= xt; j++) v[j][yc] = true;
  }
  for (int i = (0); i < (m); ++i) {
    int xc = mpx[d[i]];
    int ys = mpy[e[i]], yt = mpy[f[i]];
    for (int j = ys; j <= yt; j++) v[xc][j] = true;
  }
  X = ((int)(x).size()), Y = ((int)(y).size());
  int nex = 1;
  for (int i = (0); i < (((int)(x).size())); ++i) {
    for (int j = (0); j < (((int)(y).size())); ++j) {
      if (v[i][j]) continue;
      if (col[i][j]) continue;
      dfs(i, j, nex);
      nex++;
    }
  }
  int xz = mpx[0], yz = mpy[0];
  if (col[xz][yz] == 1)
    cout << "INF" << endl;
  else {
    ll res = 0;
    for (int i = (0); i < (((int)(x).size())); ++i) {
      for (int j = (0); j < (((int)(y).size())); ++j) {
        if (col[i][j] == col[xz][yz]) {
          ll xl = 0, yl = 0;
          if (x[i] & 1)
            xl = (x[i + 1] - x[i] + 1) / 2;
          else
            xl = (x[i + 1] - x[i]) / 2;
          if (y[j] & 1)
            yl = (y[j + 1] - y[j] + 1) / 2;
          else
            yl = (y[j + 1] - y[j]) / 2;
          res += xl * yl;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
