# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product#accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
    N,M = map(int, sysread().split())
    verticals = []
    for i in range(N):
        verticals.append(list(map(int, sysread().split())))
    horizontals = []

    for i in range(M):
        horizontals.append(list(map(int, sysread().split())))

    verticals.sort(key=lambda x: x[2])
    horizontals.sort(key=lambda x: x[0])

    to = [[] for _ in range(N * M)]
    for xi, (a,b,c) in enumerate(verticals):
        pre = None
        for yi, (d,e,f) in enumerate(horizontals):
            if a <= d and d <= b and e <= c and c <= f:
                cur = [xi * M + yi, d]# (id, d)
                if pre == None:
                    pre = cur[:]
                    continue
                to[pre[0]].append((cur[0], cur[1] - pre[1], c))# Use Green's
                to[cur[0]].append((pre[0], - cur[1] + pre[1], c))
                pre = cur[:]


    for yi, (d,e,f) in enumerate(horizontals):
        pre = None
        for xi, (a,b,c) in enumerate(verticals):
            if a <= d and d <= b and e <= c and c <= f:
                cur = [xi * M + yi, c]# (id, c)
                if pre == None:
                    pre = cur[:]
                    continue
                to[pre[0]].append((cur[0], 0, c))
                to[cur[0]].append((pre[0], 0, c))
                pre = cur[:]


    seen = [False] * (N*M)
    INF = float('inf')
    min_sq = INF
    for i in range(N*M):
        stack = []
        goal = -1
        if not seen[i] and len(to[i]) > 0:
            heappush(stack, (0, i))# (sq, node)

        while stack:
            sq, current = heappop(stack)
            seen[current] = True
            for next, dist, y in to[current]:
                if next == i:
                    goal = 1
                    sq += dist * y
                    break
                if not seen[next]:
                    heappush(stack, (sq + dist * y, next))
        if goal == 1:
            min_sq = min(min_sq, sq)

    if min_sq == INF:
        print('INF')
    else:
        print(min_sq)


if __name__ == "__main__":
    run()
