#include <bits/stdc++.h>
using namespace std;
long long int em(long long int x, long long int Mod, long long int n) {
  if (n == 0)
    return 1ll;
  else if (n % 2 == 0)
    return em((x % Mod * x % Mod) % Mod, Mod, n / 2) % Mod;
  else
    return (x % Mod * em((x % Mod * x % Mod) % Mod, Mod, (n - 1) / 2)) % Mod;
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int r, n, i, j, k, l;
  vector<pair<long long int, pair<long long int, long long int>>> v;
  cin >> r >> n;
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    cin >> j >> k >> l;
    v.push_back({j, {k, l}});
  }
  long long int dp[n + 10];
  long long int suffAns[n + 10];
  memset(dp, 0, sizeof(dp));
  memset(suffAns, 0, sizeof(suffAns));
  long long int ans = 0;
  for (i = n - 1; i >= 0; i--) {
    long long int here = 1;
    long long int ti = v[i].first;
    long long int xi = v[i].second.first;
    long long int yi = v[i].second.second;
    for (long long int j = (long long int)i + 1;
         j < (long long int)min(n, i + 2 * r + 1); j++) {
      long long int tj = v[j].first;
      long long int xj = v[j].second.first;
      long long int yj = v[j].second.second;
      if (tj - ti >= abs(xj - xi) + abs(yj - yi)) here = max(here, 1 + dp[j]);
    }
    if (i + 2 * r + 1 < n) here = max(here, 1 + suffAns[i + 2 * r + 1]);
    if (ti >= abs(xi - 1) + abs(yi - 1)) ans = max(ans, here);
    dp[i] = here;
    suffAns[i] = max(suffAns[i + 1], here);
  }
  cout << ans;
}
