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

from collections import defaultdict
from collections import deque
def main():
    n, m = mi()
    mx = defaultdict(int)
    my = defaultdict(int)
    mx[0] = 0
    my[0] = 0
    lh = []
    lv = []
    for i in range(n):
        a, b, c = mi()
        lh.append((a, b, c))
        mx[a] = 0
        mx[b] = 0
        my[c] = 0
    for i in range(m):
        c, a, b = mi()
        lv.append((a, b, c))
        my[a] = 0
        my[b] = 0
        mx[c] = 0
    xd, yd = [], []
    for key in sorted(list(mx.keys())):
        mx[key] = len(xd)
        xd.append(key)
    for key in sorted(list(my.keys())):
        my[key] = len(yd)
        yd.append(key)

    h = 2*len(xd)
    w = 2*len(yd)
    g = [[0]*w for _ in range(h)]
    for a, b, c in lh:
        a = mx[a]*2
        b = mx[b]*2
        c = my[c]*2
        for i in range(a, b+1):
            g[i][c] = -1
    for a, b, c in lv:
        a = my[a]*2
        b = my[b]*2
        c = mx[c]*2
        for i in range(a, b+1):
            g[c][i] = -1
    
    dx= [-1, 0, 1, 0]
    dy= [0, 1, 0, -1]
    xs, ys = mx[0]*2, my[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] != 0:
                continue
            g[nx][ny] = 1
            q.append((nx, ny))
    print(ans)
        
    
    
        
        
    
        



if __name__ == '__main__':
    main()