import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def compress(S):
    """ 座標圧縮 """

    zipped, unzipped = {}, {}
    for i, a in enumerate(sorted(S)):
        zipped[a] = i
        unzipped[i] = a
    return zipped, unzipped

def bfs(grid, src):
    """ BFS(グリッド、重みなし) """
    from collections import deque

    H, W = len(grid), len(grid[0])
    directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
    visited = list2d(H, W, 0)
    que = deque()
    for h, w in src:
        que.append((h, w))
        visited[h][w] = 1
    while que:
        h, w = que.popleft()
        for dh, dw in directions:
            h2 = h + dh
            w2 = w + dw
            # 外壁まで行ったら即終了
            if grid[h2][w2] == -1:
                print('INF')
                exit()
            if grid[h2][w2] == 1:
                continue
            if visited[h2][w2]:
                continue
            visited[h2][w2] = 1
            que.append((h2, w2))
    return visited

N, M = MAP()
vert = []
horz = []
S1 = set([0])
S2 = set([0])
for i in range(N):
    h1, h2, w = MAP()
    h1 *= 2
    h2 *= 2
    w *= 2
    vert.append((h1, h2, w))
    S1.add(h1)
    S1.add(h1+1)
    S1.add(h2)
    S1.add(h2+1)
    S2.add(w)
    S2.add(w+1)
for i in range(M):
    h, w1, w2 = MAP()
    h *= 2
    w1 *= 2
    w2 *= 2
    horz.append((h, w1, w2))
    S1.add(h)
    S1.add(h+1)
    S2.add(w1)
    S2.add(w1+1)
    S2.add(w2)
    S2.add(w2+1)
mxh = max(S1)
mxw = max(S2)
S1.add(mxh+1)
S2.add(mxw+1)

zph, unzph = compress(S1)
zpw, unzpw = compress(S2)
H, W = len(zph), len(zpw)

grid = list2d(H, W, -1)
for i in range(1, H-1):
    for j in range(1, W-1):
        grid[i][j] = 0
for i in range(N):
    h1, h2, w = vert[i]
    w = zpw[w] + 1
    for h in range(zph[h1]+1, zph[h2]+2):
        grid[h][w] = 1
for i in range(M):
    h, w1, w2 = horz[i]
    h = zph[h] + 1
    for w in range(zpw[w1]+1, zpw[w2]+2):
        grid[h][w] = 1

res = bfs(grid, [(zph[0], zpw[0])])
# for row in res:
#     print(row)

ans = 0
sh, sw = zph[0]&1, zpw[0]&1
for i in range(sh, H-1, 2):
    for j in range(sw, W-1, 2):
        if res[i][j]:
            hln = unzph[i+2] - unzph[i]
            wln = unzpw[j+2] - unzpw[j]
            ans += hln * wln
print(ans//4)
