1 #include<cmath>
2 #include<cstdio>
3 #include<cstdlib>
4 using namespace std;
5
6 #define inf (1<<30)
7 #define maxn 1010
8 #define maxm 10010
9 int n,m,ans,f[maxm];
10 struct node
11 {
12 int t,x,y;
13 friend inline bool operator >=(const node &a,const node &b)
14 {
15 return abs(a.x-b.x)+abs(a.y-b.y) <= a.t-b.t;
16 }
17 inline void read() { scanf("%d %d %d",&t,&x,&y); }
18 }seq[maxm];
19
20 int main()
21 {
22 freopen("1207.in","r",stdin);
23 freopen("1207.out","w",stdout);
24 scanf("%d %d",&n,&m);
25 for (int i = 1;i <= m;++i) seq[i].read();
26 for (int i = 1;i <= m;++i)
27 {
28 int best = 0;
29 for (int j = 1;j < i;++j)
30 if (f[j] > f[best]&&seq[i] >= seq[j]) best = j;
31 f[i] = f[best]+1;
32 if (f[i] > ans) ans = f[i];
33 }
34 printf("%d",ans);
35 fclose(stdin); fclose(stdout);
36 return 0;
37 }