#include <bits/stdc++.h>
using namespace std;
long long arr[100002];
long long t[100002];
long long x[100002];
long long y[100002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long r, n;
  cin >> r >> n;
  memset(arr, 0, n + 1);
  long long x1 = 1, x2 = 1;
  long long tim = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  long long answer = 0;
  t[0] = 0;
  x[0] = 1;
  y[0] = 1;
  for (int i = 0; i <= n; i++) {
    if (arr[i] || i == 0) {
      for (int j = i + 1; j <= min(n, i + 4 * r); j++) {
        if ((abs(x[j] - x[i]) + abs(y[j] - y[i])) <= (t[j] - t[i])) {
          arr[j] = max(arr[j], arr[i] + 1);
        }
      }
    }
    answer = max(answer, arr[i]);
  }
  cout << answer;
}
