#include <iostream>
#include <map>
#include <cmath>
using namespace std;
const int maxn = 25;
int main() {
int n, m;
cin >> n >> m;
map<int, int> d[maxn];
for (int i = 1, opt, x, y; i <= m; i++) {
cin >> opt >> x >> y;
if (opt == 1)
d[y][x] = 1;
else
d[y][x] = -1;
}
int bas, sum = 0;
for (int i = 0; i < n; i++) {
bas = 0;
for (int j = 1; j <= n; j++) {
bas += d[j][i];
if (i == 0 && bas == 0)
sum++;
else
sum += pow(bas, i);
}
}
cout << sum << endl;
return 0;
}