#include <bits/stdc++.h>
using namespace std;
int r, n;
int pref[100005], dp[100005];
struct pp {
  int x;
  int y;
  int t;
} a[100005];
void read() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> r >> n;
  int i;
  for (i = 1; i <= n; i++) cin >> a[i].t >> a[i].x >> a[i].y;
}
void solve() {
  a[0].x = 1;
  a[0].y = 1;
  int i, j;
  for (i = 1; i <= n; i++) {
    dp[i] = -1e9;
    for (j = max(i - 2 * r, 0); j < i; j++)
      if (abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y) <= a[i].t - a[j].t)
        dp[i] = max(dp[i], dp[j] + 1);
    if (i > 2 * r) dp[i] = max(dp[i], pref[i - 2 * r] + 1);
    pref[i] = max(pref[i - 1], dp[i]);
  }
  cout << pref[n];
}
int main() {
  read();
  solve();
  return 0;
}
