#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) {
  a = min(a, b);
}
template <class T>
inline void chmax(T &a, const T &b) {
  a = max(a, b);
}
template <class T>
inline bool kbit(const T &x, const int &k) {
  return ((x >> k) & 1LL);
}
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
void dump() { cerr << '\n'; }
template <class Head, class... Tail>
void dump(Head &&head, Tail &&...tail) {
  cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
  dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
  for (int i = 0; i < v.size(); i++)
    cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
  for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  V<int> a(n), b(n), c(n), d(m), e(m), f(m), xs, ys;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    ys.emplace_back(a[i]);
    ys.emplace_back(b[i]);
    xs.emplace_back(c[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    ys.emplace_back(d[i]);
    xs.emplace_back(e[i]);
    xs.emplace_back(f[i]);
  }
  ys.emplace_back(-INF);
  ys.emplace_back(INF);
  xs.emplace_back(-INF);
  xs.emplace_back(INF);
  xs.emplace_back(0);
  ys.emplace_back(0);
  zip(ys);
  zip(xs);
  int yn = ys.size(), xn = xs.size();
  V<V<V<int>>> ok(yn, V<V<int>>(xn, V<int>(4, 1)));
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(ys.begin(), ys.end(), a[i]) - ys.begin();
    b[i] = lower_bound(ys.begin(), ys.end(), b[i]) - ys.begin();
    c[i] = lower_bound(xs.begin(), xs.end(), c[i]) - xs.begin();
    for (int j = a[i]; j < b[i]; j++) {
      ok[j][c[i] - 1][0] = 0;
      ok[j][c[i]][2] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    d[i] = lower_bound(ys.begin(), ys.end(), d[i]) - ys.begin();
    e[i] = lower_bound(xs.begin(), xs.end(), e[i]) - xs.begin();
    f[i] = lower_bound(xs.begin(), xs.end(), f[i]) - xs.begin();
    for (int j = e[i]; j < f[i]; j++) {
      ok[d[i]][j][1] = 0;
      ok[d[i] - 1][j][3] = 0;
    }
  }
  int sx = lower_bound(xs.begin(), xs.end(), 0) - xs.begin();
  int sy = lower_bound(ys.begin(), ys.end(), 0) - ys.begin();
  queue<P> q;
  q.emplace(sy, sx);
  V<V<int>> vis(yn, V<int>(xn));
  while (!q.empty()) {
    int y = q.front().first, x = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (!ok[y][x][i] || ny < 0 || nx < 0 || ny >= yn || nx >= xn ||
          vis[ny][nx])
        continue;
      vis[ny][nx] = 1;
      q.emplace(ny, nx);
    }
  }
  ll res = 0;
  for (int i = 0; i < yn; i++) {
    for (int j = 0; j < xn; j++) {
      if (!vis[i][j]) continue;
      if (i == 0 || j == 0 || i == yn - 1 || j == xn - 1) {
        cout << 'I' << 'N' << 'F' << newl;
        return 0;
      }
      res += (ys[i + 1] - ys[i]) * (xs[i + 1] - xs[i]);
    }
  }
  cout << res << newl;
}
