#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

/*
  compress the x
  floodfill
*/

const int maxN = 1e3 + 2;
const int inf = 1e7;
int n, m, limitx, limity;
lli horizontal[3][maxN], vertical[3][maxN];

int mat[6*maxN + 1][6*maxN + 1];

int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int dfs(int x, int y)
{
  if (x < 0 || x >= limitx || y < 0 || y >= limity) return inf;
  if (mat[x][y] == 1) return 0;
  mat[x][y] = 1;
  int ans = 1;
  for (int k = 0; k < 4; k++)
    ans += dfs(x + dx[k], y + dy[k]);
  return min(inf, ans);
}

void removeRepeated(vector<lli> &arr)
{
  sort(arr.begin(), arr.end());
  arr.resize(distance(arr.begin(), unique(arr.begin(), arr.end())));
}

int main()
{
  int t = 0;
  while (scanf("%d %d", &n, &m) != EOF)
  {
    if (t++)
    {
      memset(mat, 0, sizeof(mat));
    }

    vector<lli> xs, ys;
    xs.push_back(0), ys.push_back(0);
    for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 3; j++)
        scanf("%lld", &horizontal[j][i]);
      xs.push_back(horizontal[0][i]), xs.push_back(horizontal[1][i]);
      ys.push_back(horizontal[2][i]);
    }

    for (int i = 0; i < m; i++)
    {
      for (int j = 0; j < 3; j++)
        scanf("%lld", &vertical[j][i]);
      xs.push_back(vertical[0][i]);
      ys.push_back(vertical[1][i]), ys.push_back(vertical[2][i]);
    }

    removeRepeated(xs), removeRepeated(ys);
    map<int, int> compx, compy;
    for (int i = 0; i < xs.size(); i++) compx[xs[i]] = 2*i;
    for (int i = 0; i < ys.size(); i++) compy[ys[i]] = 2*i;

    for (int i = 0; i < n; i++)
    {
      horizontal[0][i] = compx[horizontal[0][i]], horizontal[1][i] = compx[horizontal[1][i]];
      horizontal[2][i] = compy[horizontal[2][i]];
    }

    for (int i = 0; i < m; i++)
    {
      vertical[0][i] = compx[vertical[0][i]];
      vertical[1][i] = compy[vertical[1][i]], vertical[2][i] = compy[vertical[2][i]];
    }

    limitx = 2*xs.size() + 1, limity = 2*ys.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 zerox = compx[0], zeroy = compy[0];
    DEBUG
      for (int y = 0; y < limity; y++)
      {
        for (int x = 0; x < limitx; x++)
          if (x == zerox && y == zeroy) printf("x");
          else printf("%c", mat[x][y] ? '@' : ' ');
        printf("\n");
      }

    int ans = dfs(zerox, zeroy);
    if (ans >= inf) printf("INF\n");
    else printf("%d\n", ans >> 1);
  }
  return 0;
}