#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
constexpr lint inf9 = 1e9;
constexpr lint inf18 = 1e18;
inline void YES(bool condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
inline void Yes(bool condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
inline void assert_NO(bool condition) {
  if (!condition) {
    cout << "NO" << endl;
    exit(0);
  }
}
inline void assert_No(bool condition) {
  if (!condition) {
    cout << "No" << endl;
    exit(0);
  }
}
inline void assert_m1(bool condition) {
  if (!condition) {
    cout << -1 << endl;
    exit(0);
  }
}
lint power(lint base, lint exponent, lint module) {
  if (exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if (exponent) {
    lint root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}
struct position {
  lint y, x;
};
template <class T, class U>
string to_string(pair<T, U> x) {
  return to_string(x.first) + "," + to_string(x.second);
}
string to_string(string x) { return x; }
template <class itr>
void array_output(itr start, itr goal) {
  string ans;
  for (auto i = start; i != goal; i++) ans += to_string(*i) + " ";
  if (!ans.empty()) ans.pop_back();
  cout << ans << endl;
}
template <class itr>
void cins(itr first, itr last) {
  for (auto i = first; i != last; i++) {
    cin >> (*i);
  }
}
template <class T>
T gcd(T a, T b) {
  if (b)
    return gcd(b, a % b);
  else
    return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
struct combination {
  vector<lint> fact, inv;
  combination(lint sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1;
    for (lint i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2, mod);
    for (lint i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  lint P(lint n, lint r) {
    if (r < 0 || n < r) return 0;
    return (fact[n] * inv[n - r] % mod);
  }
  lint C(lint p, lint q) {
    if (q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};
template <class itr>
bool next_sequence(itr first, itr last, lint max_bound) {
  itr now = last;
  while (now != first) {
    now--;
    (*now)++;
    if ((*now) == max_bound) {
      (*now) = 0;
    } else {
      return true;
    }
  }
  return false;
}
template <class itr, class itr2>
bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2) {
  itr now = last;
  itr2 now2 = last2;
  while (now != first) {
    now--, now2--;
    (*now)++;
    if ((*now) == (*now2)) {
      (*now) = 0;
    } else {
      return true;
    }
  }
  return false;
}
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
inline lint at(lint i, lint j) { return (i >> j) & 1; }
random_device rnd;
bool is_in_board(lint y, lint x, lint H, lint W) {
  return (0 <= y && y < H && 0 <= x && x < W);
}
position mv[4] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
position wall[4] = {{0, 0}, {0, 0}, {0, 1}, {1, 0}};
signed main() {
  lint N, M;
  cin >> N >> M;
  vector<lint> y, x;
  lint A[N], B[N], C[N];
  lint D[M], E[M], F[M];
  for (lint i = 0; i < lint(N); i++) {
    cin >> A[i] >> B[i] >> C[i];
    y.push_back(A[i]);
    y.push_back(B[i]);
    x.push_back(C[i]);
  }
  for (lint i = 0; i < lint(M); i++) {
    cin >> D[i] >> E[i] >> F[i];
    y.push_back(D[i]);
    x.push_back(E[i]);
    x.push_back(F[i]);
  }
  sort((y).begin(), (y).end());
  y.erase(unique((y).begin(), (y).end()), y.end());
  sort((x).begin(), (x).end());
  x.erase(unique((x).begin(), (x).end()), x.end());
  lint H = lint(y.size()) - 1, W = lint(x.size()) - 1;
  bool row[H + 1][W], column[H][W + 1];
  memset(row, 0, sizeof(row));
  memset(column, 0, sizeof(column));
  for (lint i = 0; i < lint(N); i++) {
    lint a = lint(lower_bound((y).begin(), (y).end(), A[i]) - y.begin());
    lint b = lint(lower_bound((y).begin(), (y).end(), B[i]) - y.begin());
    lint c = lint(lower_bound((x).begin(), (x).end(), C[i]) - x.begin());
    for (lint j = lint(a); j < lint(b); j++) {
      column[j][c] = true;
    }
  }
  for (lint i = 0; i < lint(M); i++) {
    lint d = lint(lower_bound((y).begin(), (y).end(), D[i]) - y.begin());
    lint e = lint(lower_bound((x).begin(), (x).end(), E[i]) - x.begin());
    lint f = lint(lower_bound((x).begin(), (x).end(), F[i]) - x.begin());
    for (lint j = lint(e); j < lint(f); j++) {
      row[d][j] = true;
    }
  }
  lint y0 = lint(upper_bound((y).begin(), (y).end(), 0) - y.begin()) - 1;
  if (y0 < 0 || y0 >= H) {
    cout << "INF" << endl;
    return 0;
  }
  lint x0 = lint(upper_bound((x).begin(), (x).end(), 0) - x.begin()) - 1;
  if (x0 < 0 || x0 >= W) {
    cout << "INF" << endl;
    return 0;
  }
  bool movable[H][W];
  memset(movable, 0, sizeof(movable));
  queue<position> pathes;
  movable[y0][x0] = true;
  pathes.push({y0, x0});
  while (!pathes.empty()) {
    auto top = pathes.front();
    pathes.pop();
    for (lint i = 0; i < lint(4); i++) {
      lint next_y = top.y + mv[i].y;
      lint next_x = top.x + mv[i].x;
      if (mv[i].y) {
        if (row[top.y + wall[i].y][top.x + wall[i].x]) {
          continue;
        }
      } else {
        if (column[top.y + wall[i].y][top.x + wall[i].x]) {
          continue;
        }
      }
      if (!is_in_board(next_y, next_x, H, W)) {
        cout << "INF" << endl;
        return 0;
      }
      if (movable[next_y][next_x]) {
        continue;
      }
      movable[next_y][next_x] = true;
      pathes.push({next_y, next_x});
    }
  }
  lint ans = 0;
  for (lint i = 0; i < lint(H); i++) {
    for (lint j = 0; j < lint(W); j++) {
      if (movable[i][j]) {
        ans += (y[i + 1] - y[i]) * (x[i + 1] - x[i]);
      }
    }
  }
  cout << ans << endl;
}
