#include <bits/stdc++.h>
using namespace std;
bool iscompatible(int j, int i, vector<int>& x, vector<int>& y,
                  vector<int>& t) {
  return abs(x[i] - x[j]) + abs(y[i] - y[j]) <= t[i] - t[j];
}
int main() {
  int r, n;
  cin >> r >> n;
  vector<int> x(n + 1), y(n + 1), t(n + 1);
  x[0] = 1, y[0] = 1, t[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  vector<int> dp(n + 1, INT_MIN), maxupto(n + 1);
  dp[0] = maxupto[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = max(0, i - 2 * r); j < i; j++) {
      if (iscompatible(j, i, x, y, t)) dp[i] = max(dp[i], 1 + dp[j]);
    }
    if (i - 2 * r >= 0) dp[i] = max(dp[i], 1 + maxupto[i - 2 * r]);
    maxupto[i] = max(maxupto[i - 1], dp[i]);
  }
  cout << maxupto[n];
}
