#include <bits/stdc++.h>
using namespace std;
const uint64_t seed =
    std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;
const int N = 100005;
int x[N], y[N], t[N], dp[N];
void solve() {
  x[0] = 1;
  y[0] = 1;
  dp[0] = 0;
  t[0] = 0;
  int rr, n;
  cin >> rr >> n;
  int p = 0;
  int r = -1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];
    while (p < i && t[i] - t[p] > 2 * rr - 2) {
      r = max(r, dp[p]);
      p++;
    }
    if (r >= 0)
      dp[i] = r + 1;
    else
      dp[i] = -1;
    for (int j = p; j < i; j++) {
      if (dp[j] >= 0 && abs(x[i] - x[j]) + abs(y[i] - y[j]) <= t[i] - t[j]) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    ans = max(ans, dp[i]);
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  int T = 1;
  for (int i = 1; i <= T; i++) {
    solve();
  }
  cout.flush();
  return 0;
}
