#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 5e5 + 5, mod = 998244353, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long b) {
  long long c = 1;
  while (b) {
    if (b & 1) c = (c * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return c % mod;
}
long long inv(long long x) { return qpow(x, mod - 2); }
int f[N];
int x[N], y[N], t[N];
int main() {
  int _ = 1;
  for (int QAQ = 1; QAQ <= _; QAQ++) {
    int r, n;
    cin >> r >> n;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d%d", &t[i], &x[i], &y[i]);
    }
    int ans = 0;
    t[0] = 0, x[0] = y[0] = 1;
    for (int i = 1; i <= n; i++) {
      f[i] = -11111111;
      for (int j = max(0, i - 4 * r); j < i; j++) {
        if (abs(x[i] - x[j]) + abs(y[i] - y[j]) <= t[i] - t[j])
          f[i] = max(f[j] + 1, f[i]);
        if (f[i] > ans) break;
      }
      ans = max(ans, f[i]);
    }
    cout << ans << endl;
  }
}
