#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 998244353;
ll N, M;
map<l_l, ll> mp;
map<l_l, ll> others;
ll dp[100050][2];

ll beki(ll a, ll b) {
    if(b == 0) return 1;
    ll ret = beki(a, b/ 2);
    ret = ret * ret % mod;
    if(b % 2 == 1) ret = ret * a % mod;
    return ret;
}

int main() {
    //cout.precision(10);
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        if(c == 0) c = -1;
        if(abs(a - b) <= 2) mp[{a, b}] = c;
        else others[{a, b}] = c;
    }
    dp[1][0] = 1;
    dp[1][1] = 1;
    if(mp[{1,1}] == 1) dp[1][0] = 0;
    if(mp[{1,1}] == -1) dp[1][1] = 0;
    for(int i = 2; i <= N; i++) {
        for(ll now = 0; now <= 1; now++) {
            if(mp[{i, i}] == 1 && now == 0) continue;
            if(mp[{i, i}] == -1 && now == 1) continue;
            for(ll before = 0; before <= 1; before++) {
                if(mp[{i,i-1}] == 0 && mp[{i-1,i}] == 0) {
                    dp[i][now] += dp[i - 1][before] * 2;
                    //cerr << "Double " << i << " " << before << " " << now << endl;
                    continue;
                }
                if(mp[{i,i-1}] != 0 && mp[{i-1,i}] != 0) {
                    int num = before + now + max(mp[{i,i-1}], 0ll) + max(mp[{i-1,i}], 0ll);
                    if(num % 2 == 0) dp[i][now] += dp[i-1][before];
                    //cerr << "Occupied " << i << " " << before << " " << now << endl;
                    continue;
                }
                dp[i][now] += dp[i-1][before];
            }
            dp[i][now] %= mod;
            if(i == N) continue;
            if(mp[{i+1,i-1}] == 0 && mp[{i-1,i+1}] == 0) {
                dp[i][now] *= 2;
                dp[i][now] %= mod;
                continue;
            }
            if(mp[{i+1,i-1}] != 0 && mp[{i-1,i+1}] != 0) {
                int num = now + max(mp[{i+1,i-1}], 0ll) + max(mp[{i-1,i+1}], 0ll);
                if(num % 2 != 0) dp[i][now] = 0;
                continue;
            }
        }
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << dp[i][0] << " " << dp[i][1] << endl;
    }
    ll counter = 0;
    for(ll i = 1; i <= N; i++) {
        counter += 5;
        if(i <= 2) counter -= 3 - i;
        if(i >= N - 1) counter -= i - N + 2;
    }
    counter = N * N - counter;
    counter = counter / 2;
    cerr << counter << endl;
    for(auto itr = others.begin(); itr != others.end(); itr++) {
        pair<l_l, ll> now = *itr;
        if(now.second == 0) continue;
        l_l reversed;
        reversed.first = now.first.second;
        reversed.second = now.first.first;
        if(others[reversed] == 0) {
            counter--;
            continue;
        }
        //cout << now.first.first << " " << now.first.second << " " << reversed.first << " " << reversed.second << endl;
        if(reversed.first > reversed.second) continue;
        counter--;
        if(others[reversed] != now.second) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = dp[N][0] + dp[N][1];
    ans %= mod;
    cerr << ans << endl;
    ans = ans * beki(2, counter) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 39424