#include <bits/stdc++.h>
using namespace std;
const int nsz = 1e5 + 50;
int r, n, ti[nsz], x[nsz]{1}, y[nsz]{1};
int dp[nsz], val[nsz];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> r >> n;
  for (register int i = (1); i <= (n); ++i) cin >> ti[i] >> x[i] >> y[i];
  for (register int i = (1); i <= (n); ++i) {
    int jmin = max(0, i - 2 * r);
    for (register int j = (jmin); j <= (i - 1); ++j) {
      if (j && dp[j] == 0) continue;
      if (abs(x[j] - x[i]) + abs(y[i] - y[j]) <= ti[i] - ti[j])
        dp[i] = max(dp[i], dp[j] + 1);
    }
    if (jmin > 0) dp[i] = max(dp[i], val[jmin - 1] + 1);
    val[i] = max(val[i - 1], dp[i]);
  }
  cout << val[n] << '\n';
  return 0;
}
