#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
struct node {
  int t, x, y;
} a[maxn];
int dp[maxn];
int dis(int i, int j) { return abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y); }
int main() {
  int r, n;
  scanf("%d%d", &r, &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d%d", &a[i].t, &a[i].x, &a[i].y);
  memset(dp, -1, sizeof(dp));
  a[0].t = 0, a[0].x = 1, a[0].y = 1, dp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = max(0, i - 4 * r); j < i; ++j) {
      if (dp[j] == -1 || dis(i, j) + a[j].t > a[i].t) continue;
      dp[i] = max(dp[i], dp[j] + 1);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, dp[i]);
  printf("%d\n", ans);
  return 0;
}
