n,m=map(int,input().split())
k=list()
for i in range(n):
    a,b,c=map(int,input().split())
    for j in range(a,b):
        k.append([j+0.5,c])
for i in range(m):
    d,e,f=map(int,input().split())
    for j in range(e,f):
        k.append([d,j+0.5])
        
result=[[0.5,0.5]]
now=[[0.5,0.5]]    
while len(now)!=0 or len(result)>=10000000:
    l=list()
    for s in now:
        if not [s[0]+0.5,s[1]] in k:
            if not [s[0]+1,s[1]] in result:
                result.append([s[0]+1,s[1]])
                l.append([s[0]+1,s[1]])
        if not [s[0],s[1]+0.5] in k:
            if not [s[0],s[1]+1] in result:
                result.append([s[0],s[1]+1])
                l.append([s[0],s[1]+1])
        if not [s[0]-0.5,s[1]] in k:
            if not [s[0]-1,s[1]] in result:
                result.append([s[0]-1,s[1]])
                l.append([s[0]-1,s[1]])
        if not [s[0],s[1]-0.5] in k:
            if not [s[0],s[1]-1] in result:
                result.append([s[0],s[1]-1])
                l.append([s[0],s[1]-1])
    now=l
    
if len(result)>=100000000:
    print("INF")
else:
    print(len(result))