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

class Program
{
    static void Main()
    {
        try
        {
            new Program().Solve();
        }
        catch
        {
            Console.WriteLine("INF");
        }
    }

    void Solve()
    {
        var nm = ReadLongArray();
        var n = nm[0];
        var m = nm[1];

        var abc = new long[n][];
        var def = new long[m][];
        var x = new List<long>();
        var y = new List<long>();

        // dx[x] = x,y1-x,y2 のリスト
        var dx = new Dictionary<long, List<long[]>>();

        // dy[y] = x1,y-x2,y のリスト
        var dy = new Dictionary<long, List<long[]>>();

        for (var i = 0; i < n; i++)
        {
            abc[i] = ReadLongArray();

            var yy = abc[i][2];
            x.Add(abc[i][0]);
            x.Add(abc[i][1]);
            y.Add(yy);

            if (!dy.ContainsKey(yy))
                dy.Add(yy, new List<long[]>());
            dy[yy].Add(abc[i]);
        }

        for (var i = 0; i < m; i++)
        {
            def[i] = ReadLongArray();

            var xx = def[i][0];
            x.Add(def[i][0]);
            y.Add(def[i][1]);
            y.Add(def[i][2]);

            if (!dx.ContainsKey(xx))
                dx.Add(xx, new List<long[]>());
            dx[xx].Add(def[i]);
        }

        x.Sort();
        y.Sort();
        x = x.Distinct().ToList();
        y = y.Distinct().ToList();

        var st = new Point(0, 0);

        for (; x[st.X] < 0; st.X++) ;
        for (; y[st.Y] < 0; st.Y++) ;

        var done = new HashSet<Point>();

        var k = new Queue<Point>();
        k.Enqueue(st);

        Func<Point, int, int, Point> act = (po, c, d) =>
        {
            if (c != 0)
            {
                var x1 = x[po.X + (c == 1 ? 1 : 0)];
                var y1 = y[po.Y];
                var y2 = y[po.Y + 1];
                foreach (var pp in dx[x1])
                {
                    if (x1 != pp[0]) throw null;
                    if (y1 >= pp[1] && y2 <= pp[2]) return null;
                }
            }
            if (d != 0)
            {
                var x1 = x[po.X];
                var x2 = x[po.X + 1];
                var y1 = y[po.Y + (d == 1 ? 1 : 0)];
                foreach (var pp in dy[y1])
                {
                    if (y1 != pp[2]) throw null;
                    if (x1 >= pp[0] && x2 <= pp[1]) return null;
                }
            }
            return new Point(po.X + c, po.Y + d);
        };

        var size = 0L;

        while (k.Count != 0)
        {
            var po = k.Dequeue();
            if (po == null) continue;
            if (done.Contains(po)) continue;
            done.Add(po);
            k.Enqueue(act(po, +1, 0));
            k.Enqueue(act(po, -1, 0));
            k.Enqueue(act(po, 0, +1));
            k.Enqueue(act(po, 0, -1));

            size += (x[po.X + 1] - x[po.X]) * (y[po.Y + 1] - y[po.Y]);
        }

        Console.WriteLine(size);
    }

    #region Console.Read 関係
    long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    long ReadLong() => long.Parse(Console.ReadLine());
    #endregion
}

class Point
{
    public int X;
    public int Y;
    public Point(int x, int y)
    {
        X = x; Y = y;
    }
    public override bool Equals(object obj)
    {
        var p = obj as Point;
        return p.X == X && p.Y == Y;
    }
    public override int GetHashCode()
    {
        return X.GetHashCode() ^ (5000 - Y).GetHashCode();
    }
}
