import sys
n,m = map(int,input().split())

x=list()
y=list()

for i in range(n):
    x.append(list(map(int,input().split())))

for i in range(m):
    y.append(list(map(int,input().split())))


c = [i[2] for i in x]
cmax = max(c)
cmin = min(c)

d = [i[0] for i in y]
dmax = max(d)
dmin = min(d)

done = list()
ongoing = list()

ongoing.append([0,0])
ongoing.append([0,-1])
ongoing.append([-1,0])
ongoing.append([-1,-1])

while(ongoing!=[]):
    area = ongoing.pop()
    if ([area[0]+1,area[1]] not in ongoing) and ([area[0]+1,area[1]] not in done): 
        isbreak=0
        for line in y:
            if (line[0] == (area[0]+1)) and (line[1]<=area[1]) and (line[2]>=area[1]+1):
                isbreak=1
                break
        if isbreak==0:
            if area[0]+1>=dmax:
                print('INF')
                sys.exit()
            ongoing.append([area[0]+1,area[1]])


    if ([area[0]-1,area[1]] not in ongoing) and ([area[0]-1,area[1]] not in done): 
        isbreak=0
        for line in y:
            if (line[0] == (area[0])) and (line[1]<=area[1]) and (line[2]>=area[1]+1):
                isbreak=1
                break
        if isbreak==0:
            if area[0]-1<dmin:
                print('INF')
                sys.exit()
            ongoing.append([area[0]-1,area[1]])


    if ([area[0],area[1]+1] not in ongoing) and ([area[0],area[1]+1] not in done): 
        isbreak=0
        for line in x:
            if (line[2] == (area[1]+1)) and (line[0]<=area[0]) and (line[1]>=area[0]+1):
                isbreak=1
                break
        if isbreak==0:
            if area[1]+1>=cmax:
                print('INF')
                sys.exit()
            ongoing.append([area[0],area[1]+1])


    if ([area[0],area[1]-1] not in ongoing) and ([area[0],area[1]-1] not in done): 
        isbreak=0
        for line in x:
            if (line[2] == (area[1])) and (line[0]<=area[0]) and (line[1]>=area[0]+1):
                isbreak=1
                break
        if isbreak==0:
            if area[1]-1<cmin:
                print('INF')
                sys.exit()
            ongoing.append([area[0],area[1]-1])
    done.append(area)

print(len(done))
