import sys
input = sys.stdin.readline

N, M = map(int, input().split())
INF = 4 * 10**18 + 1

X = [0]
Y = [0]
X_line = []
Y_line = [] 

X_append = X.append
Y_append = Y.append
X_line_append = X_line.append
Y_line_append = Y_line.append

for i in range(N):
  A, B, C = map(int, input().split())
  if A > B:
    A, B = B, A
  X_append(A)
  X_append(B)
  Y_append(C)
  X_line_append((A,B,C)) 
  
for j in range(M):
  D, E, F = map(int, input().split())
  if E > F:
    E, F = F, E
  X_append(D)
  Y_append(E)
  Y_append(F)
  Y_line_append((D,E,F)) 

X.sort()
Y.sort()
X = list(set(X))
Y = list(set(Y))
X.sort()
Y.sort()

X_dict = {}
Y_dict = {}

i = 0
for x in X:
  X_dict[x] = 2 * i + 1
  i += 1
j = 0
for y in Y:
  Y_dict[y] = 2 * j + 1
  j += 1

G = [[0 for j in range(2*len(Y)+1)] for i in range(2*len(X)+1)]
for i_2 in range(len(X)+1):
  for j_2 in range(len(Y)+1):
    #if i % 2 == 1 or j % 2 == 1:
    #  continue #G[i][j] = 0, 奇数の箇所が面積0の要素を表す
    #else:
    if 1 <= i_2 < len(X) and 1 <= j_2 < len(Y):
      G[i_2*2][j_2*2] = (X[i_2]-X[i_2-1])*(Y[j_2]-Y[j_2-1])
    else:
      G[i_2*2][j_2*2] = INF #各ノードが持つ面積を記録、最外殻は面積無限大 
        
for (A, B, C) in X_line:
  xd = X_dict[A]
  yd = Y_dict[C] 
  #print(xd, yd, X_dict[B], len(X), len(Y))
  while xd <= X_dict[B]:
    #print(xd, yd, X_dict[B], len(X), len(Y))
    G[xd][yd] = -1 #壁は面積-1で区別
    xd += 1
    
for (D, E, F) in Y_line:
  xd = X_dict[D]
  yd = Y_dict[E] 
  while yd <= Y_dict[F]:
    G[xd][yd] = -1 #壁は面積-1で区別
    yd += 1
    
#探索により面積導出
ans = 0
que = []
visited = [[0 for _ in range(2*len(Y)+1)] for _ in range(2*len(X)+1)]
if G[X_dict[0]][Y_dict[0]] >= 0:
  #print(X_dict[0], Y_dict[0])
  que.append((X_dict[0],Y_dict[0]))
  visited[X_dict[0]][Y_dict[0]] = 1
while que and ans < INF:
  xd, yd = que.pop(-1)
  
  #print(xd, yd, G[xd][yd])
  if G[xd][yd] >= 0: 
    ans += G[xd][yd]
    G[xd][yd] = -1
    if xd < 2*len(X) and visited[xd+1][yd] == 0:
      que.append((xd+1,yd))
      visited[xd+1][yd] = 1
    if xd > 0 and visited[xd-1][yd] == 0:
      que.append((xd-1,yd))
      visited[xd-1][yd] = 1
    if yd < 2*len(Y) and visited[xd][yd+1] == 0:
      que.append((xd,yd+1))
      visited[xd][yd+1] = 1
    if yd > 0 and visited[xd][yd-1] == 0:
      que.append((xd,yd-1))
      visited[xd][yd-1] = 1
    
if ans >= INF:
  print("INF")
else:
  print(ans)
  

    