#include <bits/stdc++.h>
using namespace std;
struct pos {
  int t, x, y;
};
int dist(pos a, pos b) { return abs(a.x - b.x) + abs(a.y - b.y); }
int time(pos a, pos b) { return abs(b.t - a.t); }
int r, n, ans, dp[100005], mx[100005];
pos a[100005];
int main() {
  cin >> r >> n;
  a[0] = (pos){0, 1, 1};
  for (int i = 1; i <= n; i++) {
    cin >> a[i].t >> a[i].x >> a[i].y;
    dp[i] = INT_MIN;
    for (int j = max(0, i - 2 * r); j < i; j++) {
      if (dist(a[i], a[j]) <= time(a[i], a[j])) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    if (i > 2 * r) dp[i] = max(dp[i], mx[i - 2 * r] + 1);
    mx[i] = max(mx[i - 1], dp[i]);
  }
  cout << mx[n] << endl;
}
