#include <bits/stdc++.h>
using namespace std;
long double pi = 3.14159265;
const long long mod = 998244353;
const long long MOD = 1000000007;
long long power(long long a, long long b, long long m) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  if (b == 1) return a % m;
  long long temp = power(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b % 2) temp = (a * temp) % m;
  return temp;
}
long long modinv(long long x) { return power(x, MOD - 2, MOD); }
long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const long long N = 100005;
void solve() {
  long long r, n;
  cin >> r >> n;
  long long dp[N], t[N], x[N], y[N];
  for (long long i = 1; i < n + 1; i++) cin >> t[i] >> x[i] >> y[i];
  t[0] = 0, x[0] = 1, y[0] = 1;
  for (long long i = 1; i < N; i++) dp[i] = LONG_MIN;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = max(0ll, i - (4 * r)); j < i; j++) {
      if (t[i] - t[j] >= (abs(x[j] - x[i]) + abs(y[j] - y[i])))
        dp[i] = max(dp[j] + 1, dp[i]);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < N; i++) ans = max(ans, dp[i]);
  cout << ans << "\n";
  return;
}
int main() {
  long long test = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  for (long long testcase = 1; testcase < test + 1; testcase++) {
    solve();
  }
  return 0;
}
