using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC168F
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInt();
            int N = NM[0];
            int M = NM[1];

            var A = new List<int>();//x
            var B = new List<int>();//x
            var C = new List<int>();//y
            var D = new List<int>();//x
            var E = new List<int>();//y
            var F = new List<int>();//y
            for (int i = 0; i < N; i++)
            {
                var input = ReadInt();
                A.Add(input[0]);
                B.Add(input[1]);
                C.Add(input[2]);
            }
            for (int i = 0; i < M; i++)
            {
                var input = ReadInt();
                D.Add(input[0]);
                E.Add(input[1]);
                F.Add(input[2]);
            }

            //座標圧縮
            List<int> xList = new List<int>();
            List<int> yList = new List<int>();
            xList.AddRange(A);
            xList.AddRange(B);
            xList.AddRange(D);
            xList.Add(0);
            yList.AddRange(C);
            yList.AddRange(E);
            yList.AddRange(F);
            yList.Add(0);       //牛原点

            var toValueX = xList.Distinct().OrderBy(x => x).ToArray();
            var toValueY = yList.Distinct().OrderBy(x => x).ToArray();

            var indexFromValueTableX = toValueX.Select((value, index) => new { value, index }).ToDictionary(p => p.value, p => p.index);
            var indexFromValueTableY = toValueY.Select((value, index) => new { value, index }).ToDictionary(p => p.value, p => p.index);

            int countX = indexFromValueTableX.Count;
            int countY = indexFromValueTableY.Count;

            A = A.Select(v => indexFromValueTableX[v]).ToList();
            B = B.Select(v => indexFromValueTableX[v]).ToList();
            D = D.Select(v => indexFromValueTableX[v]).ToList();
            C = C.Select(v => indexFromValueTableY[v]).ToList();
            E = E.Select(v => indexFromValueTableY[v]).ToList();
            F = F.Select(v => indexFromValueTableY[v]).ToList();

            //
            int[,] map = new int[2 * countX - 1, 2 * countY - 1];
            for (int i = 0; i < N; i++)
            {
                for (int x = 2 * A[i]; x <= 2 * B[i]; x++)
                {
                    map[x, 2 * C[i]] = 1;
                }
            }
            for (int i = 0; i < M; i++)
            {
                for (int y = 2 * E[i]; y <= 2 * F[i]; y++)
                {
                    map[2 * D[i], y] = 1;
                }
            }
            map[2 * indexFromValueTableX[0], 2 * indexFromValueTableY[0]] = 2;

            //DrawMapforDebug(map);

            //dfs
            long ans = 0;
            int[] dx = new int[] { -1, 0, 1, 0 };
            int[] dy = new int[] { 0, 1, 0, -1 };

            //接続部をすべて塗る
            Queue<int> queX = new Queue<int>();
            Queue<int> queY = new Queue<int>();
            queX.Enqueue(2 * indexFromValueTableX[0]);
            queY.Enqueue(2 * indexFromValueTableY[0]);

            while (queX.Count > 0)
            {
                //DrawMapforDebug(map);

                int px = queX.Dequeue();
                int py = queY.Dequeue();
                for (int k = 0; k < 4; k++)
                {
                    int tx = px + dx[k];
                    int ty = py + dy[k];
                    if (tx < 0 || 2 * countX - 1 <= tx || ty < 0 || 2 * countY - 1 <= ty)
                    {
                        ans = -1;
                        continue;
                    }
                    if (map[tx, ty] > 0) continue;

                    long cand = 0;
                    if (tx % 2 == 1 && ty % 2 == 1) cand = (long)(toValueX[tx / 2 + 1] - toValueX[tx / 2]) * (toValueY[ty / 2 + 1] - toValueY[ty / 2]);
                    ans += cand;
                    queX.Enqueue(tx);
                    queY.Enqueue(ty);
                    map[tx, ty] = 2;
                }
            }

            if (ans != -1) Console.WriteLine(ans);
            else Console.WriteLine("INF");
            Console.ReadKey();
        }

        /// <summary>
        /// 二次元配列の可視化メソッド
        /// </summary>
        /// <param name="map"></param>
        static void DrawMapforDebug(int[,] map)
        {
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    Console.Write(map2[i, j] % 10);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}
