#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e3 + 1;
const int inf = 1e7;
int n, m, limit;
long long int horizontal[3][maxN], vertical[3][maxN];
int mat[6 * maxN + 1][6 * maxN + 1];
int di[4] = {-1, 1, 0, 0}, dj[4] = {0, 0, -1, 1};
int dfs(int i, int j) {
  if (i < 0 || i >= limit || j < 0 || j >= limit) return inf;
  if (mat[i][j] == 1) return 0;
  mat[i][j] = 1;
  int ans = 1;
  for (int k = 0; k < 4; k++) ans += dfs(i + di[k], j + dj[k]);
  return min(inf, ans);
}
int main() {
  int t = 0;
  while (scanf("%d %d", &n, &m) != EOF) {
    if (t++) {
      memset(mat, 0, sizeof(mat));
    }
    vector<long long int> coordinates;
    coordinates.push_back(0);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 3; j++) {
        scanf("%lld", &horizontal[j][i]);
        coordinates.push_back(horizontal[j][i]);
      }
    sort(coordinates.begin(), coordinates.end());
    coordinates.resize(distance(
        coordinates.begin(), unique(coordinates.begin(), coordinates.end())));
    map<int, int> compress;
    for (int i = 0; i < coordinates.size(); i++)
      compress[coordinates[i]] = 2 * i;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 3; j++) horizontal[j][i] = compress[horizontal[j][i]];
    coordinates.clear();
    coordinates.push_back(0);
    for (int i = 0; i < m; i++)
      for (int j = 0; j < 3; j++) {
        scanf("%lld", &vertical[j][i]);
        coordinates.push_back(vertical[j][i]);
      }
    sort(coordinates.begin(), coordinates.end());
    coordinates.resize(distance(
        coordinates.begin(), unique(coordinates.begin(), coordinates.end())));
    compress.clear();
    for (int i = 0; i < coordinates.size(); i++)
      compress[coordinates[i]] = 2 * i;
    for (int i = 0; i < m; i++)
      for (int j = 0; j < 3; j++) vertical[j][i] = compress[vertical[j][i]];
    limit = 2 * coordinates.size() + 1;
    for (int i = 0; i < n; i++)
      for (int j = horizontal[0][i]; j <= horizontal[1][i]; j++)
        mat[j][horizontal[2][i]] = 1;
    for (int i = 0; i < m; i++)
      for (int j = vertical[1][i]; j <= vertical[2][i]; j++)
        mat[vertical[0][i]][j] = 1;
    int zero = compress[0];
    if (0)
      for (int i = 0; i < limit; i++) {
        for (int j = 0; j < limit; j++)
          if (i == zero && j == zero)
            printf("x");
          else
            printf("%c", mat[i][j] ? '@' : ' ');
        printf("\n");
      }
    int ans = dfs(zero, zero);
    if (ans >= inf)
      printf("INF\n");
    else
      printf("%d\n", ans >> 1);
  }
  return 0;
}
