#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
const int inf = 1e9 + 5;
struct celeb {
  long long time;
  long long x;
  long long y;
};
void test_case() {
  long long r, n;
  cin >> r >> n;
  vector<celeb> a(n);
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    long long t, x, y;
    cin >> t >> x >> y;
    a[i] = {t, x, y};
  }
  vector<long long> dp(n);
  dp[0] = -infl;
  if (llabs(a[0].x - 1) + llabs(a[0].y - 1) <= a[0].time) dp[0] = 1;
  vector<long long> pref(n);
  pref[0] = dp[0];
  for (long long i = (long long)(1); i < (long long)(n); i++) {
    long long tans = -infl;
    if (llabs(a[i].x - 1) + llabs(a[i].y - 1) <= a[i].time) tans = 1;
    for (long long j = (long long)(i - 1);
         j >= (long long)(max(0ll, i - 2 * r)); j--) {
      if (llabs(a[i].x - a[j].x) + llabs(a[i].y - a[j].y) <=
          a[i].time - a[j].time) {
        tans = max(tans, 1 + dp[j]);
      }
    }
    if (i - 2 * r >= 0) tans = max(tans, 1 + pref[i - 2 * r]);
    pref[i] = max(pref[i - 1], tans);
    dp[i] = tans;
  }
  long long ans = *max_element(dp.begin(), dp.end());
  if (ans >= 0)
    cout << ans;
  else
    cout << 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  test_case();
  return 0;
}
