#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }
int n, m, T;
struct node {
  int x, y, t;
  bool operator<(const node b) const { return t < b.t; }
} a[maxn];
pair<int, int> mmap[505][505];
int dp[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i].t, &a[i].x, &a[i].y);
  }
  a[0] = {1, 1, 0};
  int p = 0;
  int mx = -1;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    dp[i] = -1;
    while (p < i && a[i].t - a[p].t >= 2 * n) {
      mx = max(mx, dp[p++]);
    }
    for (int j = 1; i - j >= p; j++) {
      if (dp[i - j] == -1) continue;
      int dis = abs(a[i].x - a[i - j].x) + abs(a[i].y - a[i - j].y);
      if (dis <= a[i].t - a[i - j].t) {
        dp[i] = max(dp[i], dp[i - j] + 1);
      }
    }
    if (mx != -1) dp[i] = max(dp[i], mx + 1);
    ans = max(ans, dp[i]);
  }
  cout << ans << "\n";
  return 0;
}
