// Arup Guha
// Solution to 2017 NAQ Problem: Umbral Decodinig
// 12/11/2017

import java.util.*;

public class umbraldecoding {

	public static long n;
	public static int k;
	public static int[][] pts;

	public static void main(String[] args) {

		// Read the input.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextLong();
		k = stdin.nextInt();
		pts = new int[k][3];
		for (int i=0; i<k; i++)
			for (int j=0; j<3; j++)
				pts[i][j] = stdin.nextInt();

		// Just put in all possible x values of safe pts.
		TreeSet<Integer> xSet = new TreeSet<Integer>();
		for (int i=0; i<k; i++) {
			int range = (int)(Math.cbrt(pts[i][2])+1e-9);
			for (int j=Math.max(0,pts[i][0]-range); j<=Math.min(n, pts[i][0]+range); j++)
				xSet.add(j);
		}

		// Map all unique x vals.
		TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
		int id = 0;
		while (xSet.size() > 0)
			map.put(xSet.pollFirst(), id++);

		// Store intervals here for each x.
		ArrayList<ArrayList<interval>> lists = new ArrayList<ArrayList<interval>>();
		for (int i=0; i<id; i++) lists.add(new ArrayList<interval>());

		// Go through each "umbral"
		for (int i=0; i<k; i++) {

			// Calculate valid x values.
			int range = (int)(Math.cbrt(pts[i][2])+1e-9);
			for (int j=Math.max(0,pts[i][0]-range); j<=Math.min((int)n, pts[i][0]+range); j++) {

				// For each x, calculate all range of valid y's
				int left = pts[i][2] - cube(Math.abs(pts[i][0]-j));
				int r2 = (int)Math.cbrt(left+1e-9);
				int low = Math.max(0, pts[i][1]-r2);
				int high = Math.min((int)n, pts[i][1]+r2);

				// Add this range to the list for this x.
				lists.get(map.get(j)).add(new interval(low, true));
				lists.get(map.get(j)).add(new interval(high+1, false));
			}
		}

		// Sort intervals and count pts.
		long subOut = 0;
		for (int i=0; i<id; i++) {
			Collections.sort(lists.get(i));
			subOut += solve(lists.get(i));
		}

		// Output result.
		System.out.println((n+1)*(n+1)-subOut);
	}

	// Counts the number of values specified by the intervals in list.
	public static int solve(ArrayList<interval> list) {

		int curCnt = 0, res = 0;

		// Sweep through.
		for (int i=0; i<list.size(); i++) {

			// This means the last "segment" was on.
			if (curCnt > 0) res += list.get(i).x - list.get(i-1).x;

			// Update how many segments are currently on.
			if (list.get(i).start) 	curCnt++;
			else					curCnt--;
		}

		// Ta da!
		return res;
	}

	public static int cube(int x) {
		return x*x*x;
	}
}

// Just manages a single interval [lo,hi].
class interval implements Comparable<interval> {

	public int x;
	public boolean start;

	public interval(int myx, boolean st) {
		x = myx;
		start = st;
	}

	public int compareTo(interval other) {
		if (this.x != other.x) return this.x - other.x;
		if (this.start == other.start) return 0;
		if (!this.start) return -1;
		return 1;
	}

	public String toString() {
		if (start) return ""+x+"+ ";
		else return ""+x+"- ";
	}
}