#include <bits/stdc++.h>
const int max_M = 505;
const int max_N = 1000005;
const int INF = 1e9;
int m, n, dp[max_M][max_M], F[max_N], ans;
int read() {
  char c = getchar();
  int ans = 0;
  bool flag = true;
  while (c < '0' || c > '9') flag &= (c != '-'), c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return flag ? ans : -ans;
}
void Write(int x) {
  if (x < 10)
    putchar(x + '0');
  else
    Write(x / 10), putchar(x % 10 + '0');
}
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
struct event {
  int t, x, y;
  bool operator<(const event b) const { return t < b.t; }
} E[max_N];
void update(int &x, int y) {
  if (x < y) x = y;
}
int main() {
  m = read(), n = read();
  E[0].t = 0, E[0].x = 1, E[0].y = 1;
  for (int i = 1, t, x, y; i <= n; i++)
    E[i].t = read(), E[i].x = read(), E[i].y = read();
  int ml = 0, mr = 0;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= m; j++) dp[i][j] = -INF;
  for (int i = 1; i <= n; i++) F[i] = -INF;
  dp[1][1] = 0;
  while (mr < n && E[mr + 1].t <= m) {
    ++mr;
    for (int j = E[mr].x - E[mr].t; j <= E[mr].x + E[mr].t; j++)
      if (j >= 1 && j <= m) update(F[mr], dp[j][E[mr].y] + 1);
  }
  for (int i = 1; i <= E[n].t; i++) {
    while (mr < n && E[mr + 1].t - i <= m) ++mr;
    for (int j = ml; j <= mr && E[j].t < i; j++) {
      if (E[j].y - (i - E[j].t) >= 1)
        update(dp[E[j].x][E[j].y - (i - E[j].t)], F[j]);
      if (E[j].y + (i - E[j].t) <= m)
        update(dp[E[j].x][E[j].y + (i - E[j].t)], F[j]);
    }
    while (ml <= mr && E[ml].t < i - m) ml++;
    for (int j = mr; j >= ml && E[j].t >= i; j--) {
      if (E[j].x - (E[j].t - i) >= 1)
        update(F[j], dp[E[j].x - (E[j].t - i)][E[j].y] + 1);
      if (E[j].x + (E[j].t - i) <= m)
        update(F[j], dp[E[j].x + (E[j].t - i)][E[j].y] + 1);
    }
    for (int j = ml; j <= mr && E[j].t <= i; j++) {
      if (E[j].y - (i - E[j].t) >= 1)
        update(dp[E[j].x][E[j].y - (i - E[j].t)], F[j]);
      if (E[j].y + (i - E[j].t) <= m)
        update(dp[E[j].x][E[j].y + (i - E[j].t)], F[j]);
    }
    for (int j = mr; j >= ml && E[j].t > i; j--) {
      if (E[j].x - (E[j].t - i) >= 1)
        update(F[j], dp[E[j].x - (E[j].t - i)][E[j].y] + 1);
      if (E[j].x + (E[j].t - i) <= m)
        update(F[j], dp[E[j].x + (E[j].t - i)][E[j].y] + 1);
    }
  }
  for (int i = 1; i <= n; i++) update(ans, F[i]);
  return Write(ans), 0;
}
