import sys
from collections import deque
import numpy as np

def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())

def main():
    n, m = mi()
    xd, yd = {0}, {0}
    lh = []
    lv = []
    for i in range(n):
        a, b, c = mi()
        lh.append((a, b, c))
        xd.add(a)
        xd.add(b)
        yd.add(c)
    for i in range(m):
        c, a, b = mi()
        lv.append((a, b, c))
        yd.add(a)
        yd.add(b)
        xd.add(c)
    xd = list(sorted(xd))
    yd = list(sorted(yd))
    mx, my = {}, {}
    for i, x in enumerate(xd):
        mx[x] = i
    for i, y in enumerate(yd):
        my[y] = i
    h = 2*len(xd)
    w = 2*len(yd)

    g = np.full((h, w), False, dtype=bool)
    for a, b, c in lh:
        a = mx[a]*2
        b = mx[b]*2
        c = my[c]*2
        g[a:b+1, c] = True
    for a, b, c in lv:
        a = my[a]*2
        b = my[b]*2
        c = mx[c]*2
        g[c, a:b+1] = True
    
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    xs, ys = bl(xd, 0)*2, bl(yd, 0)*2
    q = deque([(xs, ys)])
    ans = 0
    while q:
        x, y = q.popleft()
        if x == 0 or x == h-1 or y == 0 or y == w-1:
            print('INF')
            return
        if x%2 == 1 and y%2 == 1:
            ans += (xd[x//2+1]-xd[x//2])*(yd[y//2+1]-yd[y//2])

        for v in range(4):
            nx = x + dx[v]
            ny = y + dy[v]
            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                continue
            if g[nx,ny]:
                continue
            g[nx,ny] = True
            q.append((nx, ny))
    print(ans)


if __name__ == '__main__':
    main()