#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
const int M = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int dp[M];
int x[M];
int y[M];
int t[M];
int getdis(int x1, int y1, int x2, int y2) {
  return abs(x1 - x2) + abs(y1 - y2);
}
int main() {
  int r, n;
  scanf("%d%d", &r, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &t[i], &x[i], &y[i]);
    dp[i] = -inf;
  }
  x[0] = 1;
  y[0] = 1;
  t[0] = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i - 1; j >= max(0, i - 4 * r); j--) {
      if (getdis(x[i], y[i], x[j], y[j]) <= t[i] - t[j]) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
}
