#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int r, n;
int dp[maxn], mx[maxn];
int t[maxn], x[maxn], y[maxn];
long long read() {
  long long s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
int main() {
  r = read(), n = read();
  for (int i = 1; i <= n; ++i) {
    t[i] = read(), x[i] = read(), y[i] = read();
  }
  memset(dp, -1, sizeof(dp));
  x[0] = 1, y[0] = 1;
  dp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    if (i >= 2 * (r - 1) + 1) dp[i] = max(dp[i], mx[i - 2 * (r - 1) - 1] + 1);
    for (int j = i - 1; j >= max(0, i - 2 * (r - 1)); --j) {
      if (dp[j] >= 0 && t[i] - t[j] >= abs(x[i] - x[j]) + abs(y[i] - y[j])) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    mx[i] = max(mx[i - 1], dp[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, dp[i]);
  printf("%d\n", ans);
  return 0;
}
