def f_single_dot():
    from collections import deque
    N, M = [int(i) for i in input().split()]

    x, y = {0}, {0}  # 重複を除いた xy 座標の一覧 (座標圧縮に必要)
    A, B, C = [0] * N, [0] * N, [0] * N
    for i in range(N):
        A[i], B[i], C[i] = [int(i) for i in input().split()]
        x.add(A[i])
        x.add(B[i])
        y.add(C[i])
    D, E, F = [0] * M, [0] * M, [0] * M
    for i in range(M):
        D[i], E[i], F[i] = [int(i) for i in input().split()]
        x.add(D[i])
        y.add(E[i])
        y.add(F[i])
    x = sorted(x)
    y = sorted(y)

    # 座標圧縮 (壁も配列に格納するので、2 倍している)
    x_comp = {x: 2 * k for k, x in enumerate(x)}
    y_comp = {y: 2 * k for k, y in enumerate(y)}
    # 座標圧縮されたグリッドで縦横に 1 マス分進むことは実際にはどれくらい進んだことなのか
    length_x = [x[i // 2 + 1] - x[i // 2] if i % 2 else 0 for i in range(len(x) * 2 - 1)]
    length_y = [y[i // 2 + 1] - y[i // 2] if i % 2 else 0 for i in range(len(y) * 2 - 1)]

    x_size, y_size = 2 * len(x) - 1, 2 * len(y) - 1
    grid = [[0] * y_size for _ in range(x_size)]

    # 壁を埋めていく
    for i in range(N):
        a, b, c = x_comp[A[i]], x_comp[B[i]], y_comp[C[i]]
        for x in range(a, b + 1):
            grid[x][c] = 1
    for i in range(M):
        d, e, f = x_comp[D[i]], y_comp[E[i]], y_comp[F[i]]
        for y in range(e, f + 1):
            grid[d][y] = 1

    ans = 0
    diff = ((-1, 0), (1, 0), (0, -1), (0, 1))
    start_x, start_y = x_comp[0], y_comp[0]
    is_visited = [[False] * y_size for _ in range(x_size)]
    queue = deque([(start_x, start_y)])
    while queue:
        x, y = queue.pop()
        is_visited[x][y] = True
        if (x % 2) & (y % 2):
            ans += length_x[x] * length_y[y]  # 今いるマスの面積
        for dx, dy in diff:
            nx, ny = x + dx, y + dy
            if not ((0 <= x < x_size) and (0 <= y < y_size)):
                return 'INF'  # グリッドの外へ出た ⇔ 囲いになっていない
            if (not is_visited[nx][ny]) and (grid[nx][ny] == 0):
                queue.appendleft((nx, ny))
                is_visited[nx][ny] = True
    return ans

print(f_single_dot())