#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int n, r;
int t[100005];
int x[100005];
int y[100005];
int dp[100005];
int mx[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> r >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  x[0] = y[0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = -1e9;
    for (int j = max(i - 2 * r, 0); j < i; j++)
      if (abs(x[i] - x[j]) + abs(y[i] - y[j]) <= t[i] - t[j])
        dp[i] = max(dp[i], dp[j] + 1);
    if (i - 2 * r > 0) dp[i] = max(dp[i], mx[i - 2 * r] + 1);
    mx[i] = max(mx[i - 1], dp[i]);
  }
  cout << mx[n];
  return 0;
}
