#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long tim[100000];
long long x[100000];
long long y[100000];
long long dp[100000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long r, n;
    cin >> r >> n;
    for (long long i = 0; i < n; i++) cin >> tim[i] >> x[i] >> y[i];
    for (long long i = n - 1; i >= 0; i--) {
      dp[i] = 1;
      for (long long j = i + 1; j < n && j <= i + 4 * r; j++) {
        long long d = abs(x[j] - x[i]) + abs(y[j] - y[i]);
        if (d <= tim[j] - tim[i]) dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    long long maxi = 0;
    for (long long i = 0; i < n; i++)
      if (abs(x[i] - 1) + abs(y[i] - 1) <= tim[i]) maxi = max(maxi, dp[i]);
    cout << maxi;
  }
  return 0;
}
