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 x = new List<long>();
		var y = new List<long>();

		var a = new long[n]; // x
		var b = new long[n]; // x
		var c = new long[n]; // y
		for (var k = 0; k < n; k++) {
			var abc = ReadLongArray();
			x.Add(a[k] = abc[0]);
			x.Add(b[k] = abc[1]);
			y.Add(c[k] = abc[2]);
		}
		var d = new long[m]; // x
		var e = new long[m]; // y
		var f = new long[m]; // y
		var dx = new Dictionary<long, List<long>>();

		for (var k = 0; k < m; k++) {
			var def = ReadLongArray();
			x.Add(d[k] = def[0]);
			y.Add(e[k] = def[1]);
			y.Add(f[k] = def[2]);
		}

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

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

		var idxX = new Dictionary<long, long>();
		for (var i = 0; i < x.Count; i++) {
			idxX[x[i]] = i;
		}

		var idxY = new Dictionary<long, long>();
		for (var i = 0; i < y.Count; i++) {
			idxY[y[i]] = i;
		}

		var tate = new bool[x.Count - 1, y.Count];
		for (var k = 0; k < n; k++) {
			for (var ix = idxX[a[k]]; ix < idxX[b[k]]; ix++) {
				tate[ix, idxY[c[k]]] = true;
			}
		}

		var yoko = new bool[x.Count, y.Count - 1];
		for (var k = 0; k < m; k++) {
			for (var i = idxY[e[k]]; i < idxY[f[k]]; i++) {
				yoko[idxX[d[k]], i] = true;
			}
		}

		var st = new Point(0, 0);
		for (; x[st.X + 1] <= 0; st.X++) ;
		for (; y[st.Y + 1] <= 0; st.Y++) ;

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

		var gone = new HashSet<Point>();
		var size = 0L;

		while (que.Count != 0) {
			var p = que.Dequeue();
			if (!gone.Add(p)) continue;
			if (!yoko[p.X + 1, p.Y]) que.Enqueue(new Point(p.X + 1, p.Y));
			if (!yoko[p.X + 0, p.Y]) que.Enqueue(new Point(p.X - 1, p.Y));
			if (!tate[p.X, p.Y + 1]) que.Enqueue(new Point(p.X, p.Y + 1));
			if (!tate[p.X, p.Y + 0]) que.Enqueue(new Point(p.X, p.Y - 1));
			size += (x[p.X + 1] - x[p.X]) * (y[p.Y + 1] - y[p.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();
	}
}
