#include <bits/stdc++.h>
using namespace std;
int main() {
  int q = 1, i, j;
  while (q--) {
    int n, r;
    cin >> r >> n;
    vector<int> t(n + 1), x(n + 1), y(n + 1);
    t[0] = 0, x[0] = 1, y[0] = 1;
    for (i = 1; i < (n + 1); i++) {
      cin >> t[i] >> x[i] >> y[i];
    }
    vector<int> dp(n + 1, INT_MIN), pref(n + 1, INT_MIN);
    dp[0] = 0;
    for (i = 1; i < (n + 1); i++) {
      dp[i] = 1 + pref[max(i - 2 * r, 0)];
      for (j = max(0, i - 2 * r + 1); j < (i); j++) {
        if (t[i] - t[j] >= abs(x[i] - x[j]) + abs(y[i] - y[j])) {
          dp[i] = max(dp[i], dp[j] + 1);
        }
      }
      pref[i] = max({dp[i], pref[i - 1], 0});
    }
    cout << pref[n] << '\n';
  }
}
