#include <bits/stdc++.h>
using namespace std;
struct P {
  int t, x, y;
  P() : t(0), x(0), y(0){};
  P(int t, int x, int y) : t(t), x(x), y(y){};
};
int main() {
  int r, n;
  cin >> r >> n;
  vector<P> a(n + 1);
  a[0] = P(0, 1, 1);
  for (int i = 1; i < n + 1; ++i) {
    int t, x, y;
    cin >> t >> x >> y;
    a[i] = P(t, x, y);
  }
  vector<int> dp(n + 1, 0);
  int ans = 0;
  for (int i = 1; i < n + 1; ++i) {
    for (int j = max(0, i - 2000); j < i; ++j) {
      int t_ = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
      if (t_ <= a[i].t - a[j].t && (j == 0 || dp[j] != 0)) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    ans = max(ans, dp[i]);
  }
  cout << ans;
  return 0;
}
