#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double E = 1e-15;
mt19937_64 rnd(time(0));
long long n, m, r, pr[100001], dp[100001];
pair<long long, pair<long long, long long> > a[100001];
long long binpow(long long h, long long r, long long md = MOD) {
  bool t = 0;
  if (h < 0) t = 1, h = -h;
  if (r % 2 == 0) t = 0;
  long long l = 1;
  while (r) {
    if (r & 1) l *= h, l %= md;
    h *= h;
    h %= md;
    r /= 2;
  }
  if (t) l = -l;
  return l;
}
long long gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (x && y) {
    x %= y;
    swap(x, y);
  }
  return x + y;
}
void solve() {
  cin >> r >> n;
  a[0].second = make_pair(1, 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i].second.first >> a[i].second.second;
    long long o = 0;
    for (int j = i - 1; j >= max(i - r * 2, 0ll); j--)
      if (abs(a[i].second.first - a[j].second.first) +
              abs(a[i].second.second - a[j].second.second) <=
          a[i].first - a[j].first) {
        o = max(o, dp[j] + 1);
      }
    if (i > r * 2) o = max(o, pr[i - r * 2] + 1);
    if (o == 0) o = -1e9;
    pr[i] = max(pr[i - 1], o);
    dp[i] = o;
    ans = max(ans, o);
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
