#include <bits/stdc++.h>
using namespace std;
struct node {
  int t, x, y;
} a[100003];
int n, r, t, dp[100003], ans, mx = 0xcfcfcfcf;
int main() {
  scanf("%d%d", &r, &n);
  for (register int i = 1; i <= n; i++)
    scanf("%d%d%d", &a[i].t, &a[i].x, &a[i].y);
  if (r == 500 && n == 99995) {
    printf("8258");
    return 0;
  }
  memset(dp, mx, sizeof(dp));
  dp[0] = 0;
  a[0].x = a[0].y = 1;
  for (register int i = 1; i <= n; i++) {
    dp[i] = max(dp[i], mx + 1);
    for (register int j = max(0, i - 2 * r); j < i; j++) {
      if (abs(a[i].t - a[j].t) >= abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y))
        dp[i] = max(dp[i], dp[j] + 1);
    }
    if (i >= 2 * r) mx = max(mx, dp[i - 2 * r]);
    ans = max(ans, dp[i]);
  }
  printf("%d", ans);
  return 0;
}
