#include <bits/stdc++.h>
#define ll long long
#define MOD 998244353
#define CAP 100005
#define inf 10000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int ll
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
ll k;
unordered_map<int,ll> map1;

ll numWays(ll cnt, ll same){
	if(map1.find((same+1)*cnt) != map1.end()) return map1[(same+1)*cnt];
	if(cnt==0) return 1;
	if(cnt==1) {
		if(same) return k-1;
		else return k-2;
	}
	ll ans=0;
	if(same){
		ans=(k-1)*(((k-2)*numWays(cnt-2,0))%MOD);
		ans%=MOD;
		if(cnt!=2) ans+=(k-1)*numWays(cnt-2,1);
	} else {
		ans=((k-2)*(k-1)+1)*numWays(cnt-2,0);
		ans%=MOD;
		if(cnt!=2) ans+=((k-2)*numWays(cnt-2,1))%MOD;
	}
	ans%=MOD;
	map1[(same+1)*cnt] = ans;
	return ans;
}

signed main(){
	fast;
	ll n,ans=1;
	cin>>n>>k;
	std::vector<ll> v1,v2;
	for(int i=0;i<n;i++){
		ll temp;
		cin>>temp;
		if(i%2==0) v1.push_back(temp);
		else v2.push_back(temp);
	}
	std::vector<pair<ll,pair<ll,ll>>> cnt1,cnt2;
	ll c=0;
	ll prev=0;
	for(int i=0;i<v1.size();i++){
		if(v1[i]==-1) c++;
		else {
			if(c) cnt1.push_back(make_pair(c,make_pair(prev,v1[i])));
			prev = v1[i];
			c=0;
		}
	}
	if(c) cnt1.push_back(make_pair(c,make_pair(prev,0)));
	c=0;
	prev=0;
	for(int i=0;i<v2.size();i++){
		if(v2[i]==-1) c++;
		else {
			if(c) cnt2.push_back(make_pair(c,make_pair(prev,v2[i])));
			prev = v2[i];
			c=0;
		}
	}
	if(c) cnt2.push_back(make_pair(c,make_pair(prev,0)));

	for(int i=0;i<cnt1.size();i++){
		ll count = cnt1[i].first;
		ll p = cnt1[i].second.first;
		ll nx = cnt1[i].second.second;
		if(count==0) continue;
		if(p==0&&nx==0){
			ans*=k;
			ans%=MOD;
			ans*=power(k-1,count-1);
		}
		else if(p==0||nx==0) ans*=power(k-1,count);
		else if(p==nx) ans*=numWays(count,1);
		else ans*=numWays(count,0);
		ans%=MOD;
	}
	for(int i=0;i<cnt2.size();i++){
		ll count = cnt2[i].first;
		ll p = cnt2[i].second.first;
		ll nx = cnt2[i].second.second;
		if(count==0) continue;
		if(p==0&&nx==0){
			ans*=k;
			ans%=MOD;
			ans*=power(k-1,count-1);
		}
		else if(p==0||nx==0) ans*=power(k-1,count);
		else if(p==nx) ans*=numWays(count,1);
		else ans*=numWays(count,0);
		ans%=MOD;
	}

	for(int i=1;i<v1.size();i++)
		if(v1[i]==v1[i-1]&&v1[i]!=-1) ans=0;
	for(int i=1;i<v2.size();i++)
		if(v2[i]==v2[i-1]&&v2[i]!=-1) ans=0;

	cout<<ans;
}


#include <bits/stdc++.h>
#define ll long long
#define MOD 998244353
#define CAP 100005
#define inf 10000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int ll
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
ll k;
unordered_map<ll,ll> map1;

ll numWays(ll cnt, ll same){
	if(map1.find((same+1)*cnt) != map1.end()) return map1[(same+1)*cnt];
	if(cnt==0) return 1;
	if(cnt==1) {
		if(same) return k-1;
		else return k-2;
	}
	ll ans=0;
	if(same){
		ans=(k-1)*(((k-1)*numWays(cnt-2,0))%MOD);
		ans%=MOD;
		if(cnt!=2) ans+=(k-1)*numWays(cnt-2,1);
	} else {
		ans=(k-2)*(((k-3)*numWays(cnt-2,0))%MOD);
		ans%=MOD;
		ans+=2*(((k-2)*numWays(cnt-2,0))%MOD);
		ans%=MOD;
		ans+=numWays(cnt-2,0);
		ans%=MOD;
		if(cnt!=2) ans+=((k-2)*numWays(cnt-2,1))%MOD;
	}
	ans%=MOD;
	map1[(same+1)*cnt] = ans;
	return ans;
}

signed main(){
	fast;
	ll n,ans=1;
	cin>>n>>k;
	std::vector<ll> v1,v2;
	for(int i=0;i<n;i++){
		ll temp;
		cin>>temp;
		if(i%2==0) v1.push_back(temp);
		else v2.push_back(temp);
	}
	std::vector<pair<ll,pair<ll,ll>>> cnt1,cnt2;
	ll c=0;
	ll prev=0;
	for(int i=0;i<v1.size();i++){
		if(v1[i]==-1) c++;
		else {
			if(c) cnt1.push_back(make_pair(c,make_pair(prev,v1[i])));
			prev = v1[i];
			c=0;
		}
	}
	if(c) cnt1.push_back(make_pair(c,make_pair(prev,0)));
	c=0;
	prev=0;
	for(int i=0;i<v2.size();i++){
		if(v2[i]==-1) c++;
		else {
			if(c) cnt2.push_back(make_pair(c,make_pair(prev,v2[i])));
			prev = v2[i];
			c=0;
		}
	}
	if(c) cnt2.push_back(make_pair(c,make_pair(prev,0)));

	for(int i=0;i<cnt1.size();i++){
		ll count = cnt1[i].first;
		ll p = cnt1[i].second.first;
		ll nx = cnt1[i].second.second;
		if(count==0) continue;
		if(p==0&&nx==0){
			ans*=k;
			ans%=MOD;
			ans*=power(k-1,count-1);
		}
		else if(p==0||nx==0) ans*=power(k-1,count);
		else if(p==nx) ans*=numWays(count,1);
		else ans*=numWays(count,0);
		ans%=MOD;
	}
	for(int i=0;i<cnt2.size();i++){
		ll count = cnt2[i].first;
		ll p = cnt2[i].second.first;
		ll nx = cnt2[i].second.second;
		if(count==0) continue;
		if(p==0&&nx==0){
			ans*=k;
			ans%=MOD;
			ans*=power(k-1,count-1);
		}
		else if(p==0||nx==0) ans*=power(k-1,count);
		else if(p==nx) ans*=numWays(count,1);
		else ans*=numWays(count,0);
		ans%=MOD;
	}

	for(int i=1;i<v1.size();i++)
		if(v1[i]==v1[i-1]&&v1[i]!=-1) ans=0;
	for(int i=1;i<v2.size();i++)
		if(v2[i]==v2[i-1]&&v2[i]!=-1) ans=0;

	cout<<ans;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        ll r = i;
        ll cur = 1;
        cur = k;
        if (i >= 2)
            cur--;
        ll c = 0;
        if (i < n - 2 && a[i + 2] != -1 && (i < 2 || a[i + 2] != a[i - 2]))
            cur--;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1) {
                cur = (cur * (k - 1)) % mod;
            }
            else {
                c = a[r + 2];
                ll dp[2];
                dp[0] = (k - 1 - (i >= 2 && a[i - 2] != c));
                dp[1] = (i < 2 || a[i - 2] != c);
                for (int t = i + 2; t <= r; t += 2){
                    ll nw[2];
                    nw[1] = dp[0];
                    nw[0] = dp[1] * (k - 1) % mod;
                    dp[0] = nw[0];
                    dp[1] = nw[1];
                }
                cur = (cur * (k - 1) - dp[1]) % mod;
                if (cur < 0)
                    cur += mod;
            }
        }
        if (cur < 0)
            cur += mod;
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

ll bin_pow(ll x, ll n){
    if (n == 0)
        return 1;
    ll t = bin_pow(x, n / 2);
    t = t * t % mod;
    if (n % 2)
        t = t * x % mod;
    return t;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    ll rev = bin_pow(k - 1, mod - 2);
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        int r = i;
        ll cur = 1;
        cur = k;
        ll dp = 1;
        if (i >= 2)
            cur--;
        if (i < n - 2 && a[i + 2] != -1 && (i < 2 || a[i + 2] != a[i - 2]))
            cur--;
        ll last = 1;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1) {
                cur = (cur * (k - 1)) % mod;
                dp = (dp * (k - 1)) % mod;
            }
            else {
                ll prev = cur * rev % mod;
                if (r == i + 2)
                    prev = 1;
                dp = (dp * (k - 1)) % mod;
                cur = (cur * (k - 1) - dp) % mod;
            }
        }
        if (cur < 0)
            cur += mod;
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

ll bin_pow(ll x, ll n){
    if (n == 0)
        return 1;
    ll t = bin_pow(x, n / 2);
    t = t * t % mod;
    if (n % 2)
        t = t * x % mod;
    return t;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        int r = i;
        ll cur = 1;
        ll t = 1;
        cur = k;
        if (i >= 2)
            cur--;
        if (i < n - 2 && a[i + 2] != -1)
            cur--;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1)
                cur = (cur * (k - 1)) % mod;
            else
                cur = (cur * (k - 2)) % mod;
            t++;
        }
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

ll bin_pow(ll x, ll n){
    if (n == 0)
        return 1;
    ll t = bin_pow(x, n / 2);
    t = t * t % mod;
    if (n % 2)
        t = t * x % mod;
    return t;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll rev = bin_pow(k - 1, mod - 2);
    ll a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        ll r = i;
        ll cur = 1;
        cur = k;
        ll dp = 1;
        if (i >= 2)
            cur--;
        if (i < n - 2 && a[i + 2] != -1 && (i < 2 || a[i + 2] != a[i - 2]))
            cur--;
        ll last = 1;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1) {
                cur = (cur * (k - 1)) % mod;
                dp = (dp * (k - 1)) % mod;
            }
            else {
                ll prev = cur * rev % mod;
                if (r == i + 2)
                    prev = 1;
                dp = (dp * (k - 1)) % mod;
                cur = (cur * (k - 1) - dp) % mod;
            }
        }
        if (cur < 0)
            cur += mod;
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

ll bin_pow(ll x, ll n){
    if (n == 0)
        return 1;
    ll t = bin_pow(x, n / 2);
    t = t * t % mod;
    if (n % 2)
        t = t * x % mod;
    return t;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        int r = i;
        ll cur = 1;
        ll t = 1;
        cur = k;
        if (i >= 2)
            cur--;
        if (i < n - 2 && a[i + 2] != -1 && (i < 2 || a[i + 2] != a[i - 2]))
            cur--;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1)
                cur = (cur * (k - 1)) % mod;
            else
                cur = (cur * (k - 2)) % mod;
            t++;
        }
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        ll r = i;
        ll cur = 1;
        cur = k;
        if (i >= 2)
            cur--;
        ll c = 0;
        if (i < n - 2 && a[i + 2] != -1 && (i < 2 || a[i + 2] != a[i - 2]))
            cur--;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1) {
                cur = (cur * (k - 1)) % mod;
            }
            else {
                c = a[r + 2];
                ll dp[2];
                if (i < 2)
                    dp[0] = k - 1;
                else if (a[i - 2] == c)
                    dp[0] = k - 1;
                else
                    dp[0] = k - 2;
                dp[1] = (i < 2 || a[i - 2] != c);
                for (int t = i + 2; t <= r; t += 2){
                    ll nw[2];
                    nw[1] = dp[0];
                    nw[0] = (dp[1] * (k - 1) % mod + dp[0] * (k - 1)) % mod;
                    dp[0] = nw[0];
                    dp[1] = nw[1];
                }
                cur = (cur * (k - 1) - dp[1]) % mod;
                if (cur < 0)
                    cur += mod;
            }
        }
        if (cur < 0)
            cur += mod;
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

ll bin_pow(ll x, ll n){
    if (n == 0)
        return 1;
    ll t = bin_pow(x, n / 2);
    t = t * t % mod;
    if (n % 2)
        t = t * x % mod;
    return t;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        int r = i;
        ll cur = 1;
        ll t = 1;
        cur = k;
        if (i >= 2)
            cur--;
        if (i < n - 2 && a[i + 2] != -1)
            cur--;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1)
                cur = (cur * (k - t)) % mod;
            else
                cur = (cur * (k - t - 1)) % mod;
            t++;
        }
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        ll r = i;
        ll cur = 1;
        cur = k;
        if (i >= 2)
            cur--;
        ll c = 0;
        if (i < n - 2 && a[i + 2] != -1 && (i < 2 || a[i + 2] != a[i - 2]))
            cur--;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1) {
                cur = (cur * (k - 1)) % mod;
            }
            else {
                c = a[r + 2];
                ll dp[2];
                if (i < 2)
                    dp[0] = k - 1;
                else if (a[i - 2] == c)
                    dp[0] = k - 1;
                else
                    dp[0] = k - 2;
                dp[1] = (i < 2 || a[i - 2] != c);
                for (int t = i + 2; t <= r; t += 2){
                    ll nw[2];
                    nw[1] = dp[0];
                    nw[0] = (dp[1] * (k - 1) % mod + dp[0] * (k - 2) % mod) % mod;
                    dp[0] = nw[0];
                    dp[1] = nw[1];
                }
                cur = (cur * (k - 1) - dp[1]) % mod;
                if (cur < 0)
                    cur += mod;
            }
        }
        if (cur < 0)
            cur += mod;
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 2e5 + 5;
const ll mod = 998244353;
const ll INF = 1e9;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 2; i++)
        if (a[i] != -1 && a[i] == a[i + 2]){
            cout << 0;
            return 0;
        }
    bool used[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] != -1 || used[i])
            continue;
        used[i] = true;
        ll r = i;
        ll cur = 1;
        cur = k;
        if (i >= 2)
            cur--;
        ll c = 0;
        if (i < n - 2 && a[i + 2] != -1 && (i < 2 || a[i + 2] != a[i - 2]))
            cur--;
        while (r + 2 < n && a[r + 2] == -1) {
            r += 2;
            used[r] = true;
            if (r + 2 >= n || a[r + 2] == -1) {
                cur = (cur * (k - 1)) % mod;
            }
            else {
                c = a[r + 2];
                ll dp[2];
                dp[0] = (k - 1 - (i >= 2 && a[i - 2] != c));
                dp[1] = (i >= 2 && a[i - 2] != c);
                for (int t = i + 2; t <= r; t += 2){
                    ll nw[2];
                    nw[1] = dp[0];
                    nw[0] = dp[1] * (k - 1) % mod;
                    dp[0] = nw[0];
                    dp[1] = nw[1];
                }
                cur = (cur * (k - 1) - dp[1]) % mod;
                if (cur < 0)
                    cur += mod;
            }
        }
        if (cur < 0)
            cur += mod;
        ans = (ans * cur) % mod;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f
typedef long long ll;
using namespace std;
const int N=2e5+10,mod=998244353;
ll dp[N],a[N];
int n,k,cnt;
inline p(int x){
	if(x<1||x>n)return 0;
	return a[x];
}
inline Mod(ll x){
	return (x%mod+mod)%mod;
}
int main(){
    scanf("%d%d",&n,&k);
    for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
    	if(a[i]==-1){
    		if(p(i-2)&&p(i+2)){
				if(p(i+2)==-1){
					dp[i]=dp[i-1]*(k-1)%mod;
				}
				else if(p(i-2)==-1){
					dp[i]=Mod(dp[i-1]*(k-1)%mod-dp[i-3]);
				}
				else if(p(i+2)==p(i-2)){
					dp[i]=dp[i-1]*(k-1)%mod;
				}
				else dp[i]=dp[i-1]*(k-2)%mod;
			}
			else if(p(i-2)){
				dp[i]=dp[i-1]*(k-1)%mod;
			}
			else if(p(i+2)>0){
				dp[i]=dp[i-1]*(k-1)%mod;
			}
			else{
				dp[i]=dp[i-1]*k%mod;
			}
		}
		else dp[i]=dp[i-1];
		if(p(i+1)>0&&p(i-1)>0&&p(i+1)==p(i-1)){
			dp[i]=0;
		}
	}
	printf("%lld",dp[n]);
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f
typedef long long ll;
using namespace std;
const int N=2e5+10,mod=998244353;
ll dp[N],a[N];
int n,k,cnt;
inline p(int x){
	if(x<1||x>n)return 0;
	return a[x];
}
inline Mod(ll x){
	return (x%mod+mod)%mod;
}
int main(){
    scanf("%d%d",&n,&k);
    for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
    	if(a[i]==-1){
    		if(p(i-2)&&p(i+2)){
				if(p(i+2)==-1){
					dp[i]=dp[i-1]*(k-1)%mod;
				}
				else if(p(i-2)==-1){
					dp[i]=Mod(dp[i-1]*(k-1)%mod-dp[i-3]);
				}
				else if(p(i+2)==p(i-2)){
					dp[i]=dp[i-1]*(k-1)%mod;
				}
				else dp[i]=dp[i-1]*(k-2)%mod;
			}
			else if(p(i-2)){
				dp[i]=dp[i-1]*(k-1)%mod;
			}
			else if(p(i+2)>0){
				dp[i]=dp[i-1]*(k-1)%mod;
			}
			else{
				dp[i]=dp[i-1]*k%mod;
			}
		}
		else if(p(i+2)>0&&p(i-2)>0&&p(i+2)==p(i-2)){
			dp[i]=0;
		}
		else dp[i]=dp[i-1];
	}
	printf("%lld",dp[n]);
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f
typedef long long ll;
using namespace std;
const int N=2e5+10,mod=998244353;
ll dp[N],a[N];
int n,k,cnt;
inline p(int x){
	if(x<1||x>n)return 0;
	return a[x];
}
inline Mod(ll x){
	return (x%mod+mod)%mod;
}
int main(){
    scanf("%d%d",&n,&k);
    for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
    	if(a[i]==-1){
    		if(p(i-2)&&p(i+2)){
				if(p(i+2)==-1){
					dp[i]=dp[i-1]*(k-1)%mod;
				}
				else if(p(i-2)==-1){
					dp[i]=Mod(dp[i-1]*(k-1)%mod-dp[i-3]);
				}
				else if(p(i+2)==p(i-2)){
					dp[i]=dp[i-1]*(k-1)%mod;
				}
				else dp[i]=dp[i-1]*(k-2)%mod;
			}
			else if(p(i-2)){
				dp[i]=dp[i-1]*(k-1)%mod;
			}
			else if(p(i+2)>0){
				dp[i]=dp[i-1]*(k-1)%mod;
			}
			else{
				dp[i]=dp[i-1]*k%mod;
			}
		}
		else dp[i]=dp[i-1];
	}
	printf("%lld",dp[n]);
	return 0;
}


//by Shriram Lokhande
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define testcases(t) int t,myzx;cin>>myzx;forsn(t,1,myzx+1)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define ln "\n"
#define kyahai(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<ln; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t\t";
	err(++it, args...);
}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end()
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//like set just find_by_order() and order_of_key() are extra

#pragma GCC optimize ("-O3")
template < typename tp > void in( tp & dig ){
    char ch=getchar();dig=0;ll flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}
const int LIM = 2e5+5 ,MOD = 998244353;
const double EPS = 1e-9;
int n , m , t , x ,y ,k;

ll dp[LIM];
ll dda(ll a,ll b){
	return (a+b) % MOD;
}
ll mul(ll a,ll b){
	return a*b % MOD;
}
ll powmod(ll a,ll b){
	a = a%MOD;b = b%(MOD-1);ll ans = 1;
	while(b > 0){
		if(b&1)
			ans = ans*a % MOD;
		a = a*a % MOD;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
	return powmod(b,MOD-2);
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	ll ans = 1;
	ll a[n];
	dp[0] = 0;
	dp[1] = k-2;
	forsn(i,2,LIM){
		dp[i] = dda( mul(powmod(k-1,i-2),mul(k-2,k-2)) , mul(dp[i-2],k-1));
	}
	forn(i,n) cin>>a[i];
	ll l = -1,r= -1 ;
	ll cnt = 0;
	for(int i = 0;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			if(cnt == 0) ans = 0;
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cnt = 0;
	l = -1, r = -1;
	for(int i = 1;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1 ){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			if(cnt == 0) ans = 0;
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
//		kyahai(cnt);
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cout<<ans<<ln;

}


//by Shriram Lokhande
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define testcases(t) int t,myzx;cin>>myzx;forsn(t,1,myzx+1)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define ln "\n"
#define kyahai(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<ln; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t\t";
	err(++it, args...);
}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end()
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//like set just find_by_order() and order_of_key() are extra

#pragma GCC optimize ("-O3")
template < typename tp > void in( tp & dig ){
    char ch=getchar();dig=0;ll flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}
const int LIM = 2e5+5 ,MOD = 998244353;
const double EPS = 1e-9;
int n , m , t , x ,y ,k;

ll dp[LIM];
ll dda(ll a,ll b){
	return (a+b) % MOD;
}
ll mul(ll a,ll b){
	return a*b % MOD;
}
ll powmod(ll a,ll b){
	a = a%MOD;b = b%(MOD-1);ll ans = 1;
	while(b > 0){
		if(b&1)
			ans = ans*a % MOD;
		a = a*a % MOD;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
	return powmod(b,MOD-2);
}

v64 qw[2];
ll f(int s){
	int n = (int) qw[s].size();
	ll l = 0, r = n-1;
	ll res= 1;
	while(qw[s][l] == -1) l++;
	if(l == n) return mul(k,powmod(k-1,n-1));
	while(qw[s][r] == -1) r--;
	res = mul(res,powmod(k-1,l));
	res = mul(res,powmod(k-1,n-1-r));
	y = qw[s][l];
	ll cnt = 0;
	forsn(i,l+1,r+1){
		if(qw[s][i] == -1) cnt++;
		else{
			if(qw[s][i] != y){
				res = mul(res,dp[cnt]);
			}else{
				if(cnt == 0) res =0;
				else{
					res = mul(res,mul(k-1,dp[cnt-1]));
				}
			}
			cnt = 0;
		}
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	dp[0] = 1;
	dp[1] = k-2;
	forsn(i,2,LIM){
		dp[i] = dda( mul(dp[i-1],k-2) , mul(dp[i-2],k-1));
	}
	forn(i,n) {
		cin>>x;
		if(i%2) qw[1].pb(x);
		else qw[0].pb(x);
	}
	cout<<mul(f(0),f(1))<<ln;

}


//by Shriram Lokhande
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define testcases(t) int t,myzx;cin>>myzx;forsn(t,1,myzx+1)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define ln "\n"
#define kyahai(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<ln; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t\t";
	err(++it, args...);
}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end()
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//like set just find_by_order() and order_of_key() are extra

#pragma GCC optimize ("-O3")
template < typename tp > void in( tp & dig ){
    char ch=getchar();dig=0;ll flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}
const int LIM = 2e5+5 ,MOD = 998244353;
const double EPS = 1e-9;
int n , m , t , x ,y ,k;

ll dp[LIM];
ll dda(ll a,ll b){
	return (a+b) % MOD;
}
ll mul(ll a,ll b){
	return a*b % MOD;
}
ll powmod(ll a,ll b){
	a = a%MOD;b = b%(MOD-1);ll ans = 1;
	while(b > 0){
		if(b&1)
			ans = ans*a % MOD;
		a = a*a % MOD;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
	return powmod(b,MOD-2);
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	ll ans = 1;
	ll a[n];
	dp[0] = 1;
	dp[1] = k-2;
	forsn(i,2,LIM){
		dp[i] = dda( mul(dp[i-1],k-2) , mul(dp[i-2],k-1));
	}
	forn(i,n) cin>>a[i];
	ll l = -1,r= -1 ;
	ll cnt = 0;
	for(int i = 0;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			if(cnt == 0) ans = 0;
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cnt = 0;
	l = -1, r = -1;
	for(int i = 1;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1 ){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			if(cnt == 0) ans = 0;
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
//		kyahai(cnt);
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cout<<ans<<ln;

}


//by Shriram Lokhande
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define testcases(t) int t,myzx;cin>>myzx;forsn(t,1,myzx+1)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define ln "\n"
#define kyahai(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<ln; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t\t";
	err(++it, args...);
}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end()
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//like set just find_by_order() and order_of_key() are extra

#pragma GCC optimize ("-O3")
template < typename tp > void in( tp & dig ){
    char ch=getchar();dig=0;ll flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}
const int LIM = 2e5+5 ,MOD = 998244353;
const double EPS = 1e-9;
int n , m , t , x ,y ,k;

ll dp[LIM];
ll dda(ll a,ll b){
	return (a+b) % MOD;
}
ll mul(ll a,ll b){
	return a*b % MOD;
}
ll powmod(ll a,ll b){
	a = a%MOD;b = b%(MOD-1);ll ans = 1;
	while(b > 0){
		if(b&1)
			ans = ans*a % MOD;
		a = a*a % MOD;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
	return powmod(b,MOD-2);
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	ll ans = 1;
	ll a[n];
	dp[0] = 0;
	dp[1] = k-2;
	forsn(i,2,LIM){
		dp[i] = dda( mul(powmod(k-1,i-2),mul(k-2,k-2)) , mul(dp[i-2],k-1));
	}
	forn(i,n) cin>>a[i];
	ll l = -1,r= -1 ;
	ll cnt = 0;
	for(int i = 0;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cnt = 0;
	l = -1, r = -1;
	for(int i = 1;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1 ){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
//		kyahai(cnt);
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cout<<ans<<ln;

}


//by Shriram Lokhande
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define testcases(t) int t,myzx;cin>>myzx;forsn(t,1,myzx+1)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define ln "\n"
#define kyahai(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<ln; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t\t";
	err(++it, args...);
}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end()
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//like set just find_by_order() and order_of_key() are extra

#pragma GCC optimize ("-O3")
template < typename tp > void in( tp & dig ){
    char ch=getchar();dig=0;ll flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}
const int LIM = 2e5+5 ,MOD = 998244353;
const double EPS = 1e-9;
int n , m , t , x ,y ,k;

ll dp[LIM];
ll dda(ll a,ll b){
	return (a+b) % MOD;
}
ll mul(ll a,ll b){
	return a*b % MOD;
}
ll powmod(ll a,ll b){
	a = a%MOD;b = b%(MOD-1);ll ans = 1;
	while(b > 0){
		if(b&1)
			ans = ans*a % MOD;
		a = a*a % MOD;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
	return powmod(b,MOD-2);
}

ll ans = 1;
v32 qw[2];
ll f(int s){
	int n = (int) qw[s].size();
	ll l = 0, r = n-1;
	ll res= 1;
	while(qw[s][l] == -1) l++;
	if(l == n) return mul(k,powmod(k-1,n-1));
	while(qw[s][r] == -1) r--;
	res = mul(res,powmod(k-1,l));
	res = mul(res,powmod(k-1,n-1-r));
	y = qw[s][l];
	ll cnt = 0;
	forsn(i,l+1,r+1){
		if(qw[s][i] == -1) cnt++;
		else{
			if(qw[s][i] != y){
				res = mul(res,dp[cnt]);
			}else{
				if(cnt == 0) res =0;
				else{
					res = mul(res,mul(k-1,dp[cnt-1]));
				}
			}
			cnt = 0;
		}
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	ll ans = 1;
	ll a[n];
	dp[0] = 1;
	dp[1] = k-2;
	forsn(i,2,LIM){
		dp[i] = dda( mul(dp[i-1],k-2) , mul(dp[i-2],k-1));
	}
	forn(i,n) {
		cin>>x;
		if(i%2) qw[1].pb(x);
		else qw[0].pb(x);
	}
	cout<<mul(f(0),f(1))<<ln;

}


//by Shriram Lokhande
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define testcases(t) int t,myzx;cin>>myzx;forsn(t,1,myzx+1)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define ln "\n"
#define kyahai(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<ln; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t\t";
	err(++it, args...);
}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end()
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//like set just find_by_order() and order_of_key() are extra

#pragma GCC optimize ("-O3")
template < typename tp > void in( tp & dig ){
    char ch=getchar();dig=0;ll flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}
const int LIM = 2e5+5 ,MOD = 998244353;
const double EPS = 1e-9;
int n , m , t , x ,y ,k;

ll dp[LIM];
ll dda(ll a,ll b){
	return (a+b) % MOD;
}
ll mul(ll a,ll b){
	return a*b % MOD;
}
ll powmod(ll a,ll b){
	a = a%MOD;b = b%(MOD-1);ll ans = 1;
	while(b > 0){
		if(b&1)
			ans = ans*a % MOD;
		a = a*a % MOD;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
	return powmod(b,MOD-2);
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	ll ans = 1;
	ll a[n];
	dp[0] = 0;
	dp[1] = k-2;
	forsn(i,2,LIM){
		dp[i] = dda( mul(dp[i-1],k-2) , mul(dp[i-2],k-1));
	}
	forn(i,n) cin>>a[i];
	ll l = -1,r= -1 ;
	ll cnt = 0;
	for(int i = 0;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			if(cnt == 0) ans = 0;
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cnt = 0;
	l = -1, r = -1;
	for(int i = 1;i<n;i+=2){
		cnt++;
		if(a[i] == -1) continue;
		r = a[i];
		cnt--;
		if(l == -1 ){
			ans = mul(ans,powmod(k-1,cnt));
		}else if(l == r){
			if(cnt == 0) ans = 0;
			ans = mul(ans,mul(k-1,dp[cnt-1]));
		}else{
			ans = mul(ans,dp[cnt]);
		}
//		kyahai(i,ans,cnt,l,r);
		cnt = 0;
		l = a[i];
	}
	if(l == -1 && cnt != 0){
		ans = mul(ans,mul(k,powmod(k-1,cnt-1)));
//		kyahai(cnt);
	}else{
		ans = mul(ans,powmod(k-1,cnt));
	}

	cout<<ans<<ln;

}


//by Shriram Lokhande
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define testcases(t) int t,myzx;cin>>myzx;forsn(t,1,myzx+1)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define ln "\n"
#define kyahai(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<ln; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t\t";
	err(++it, args...);
}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end()
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//like set just find_by_order() and order_of_key() are extra

#pragma GCC optimize ("-O3")
template < typename tp > void in( tp & dig ){
    char ch=getchar();dig=0;ll flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}
const int LIM = 2e5+5 ,MOD = 998244353;
const double EPS = 1e-9;
int n , m , t , x ,y ,k;

ll dp[LIM];
ll dda(ll a,ll b){
	return (a+b) % MOD;
}
ll mul(ll a,ll b){
	return a*b % MOD;
}
ll powmod(ll a,ll b){
	a = a%MOD;b = b%(MOD-1);ll ans = 1;
	while(b > 0){
		if(b&1)
			ans = ans*a % MOD;
		a = a*a % MOD;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
	return powmod(b,MOD-2);
}

v64 qw[2];
ll f(int s){
	int n = (int) qw[s].size();
	ll l = 0, r = n-1;
	ll res= 1;
	while(qw[s][l] == -1) l++;
	if(l == n) return mul(k,powmod(k-1,n-1));
	while(qw[s][r] == -1) r--;
	res = mul(res,powmod(k-1,l));
	res = mul(res,powmod(k-1,n-1-r));
	y = qw[s][l];
	ll cnt = 0;
	forsn(i,l+1,r+1){
		if(qw[s][i] == -1) cnt++;
		else{
			if(qw[s][i] != y){
				res = mul(res,dp[cnt]);
			}else{
				if(cnt == 0) res =0;
				else{
					res = mul(res,mul(k-1,dp[cnt-1]));
				}
			}
			cnt = 0;
			y = qw[s][i];
		}
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	dp[0] = 1;
	dp[1] = k-2;
	forsn(i,2,LIM){
		dp[i] = dda( mul(dp[i-1],k-2) , mul(dp[i-2],k-1));
	}
	forn(i,n) {
		cin>>x;
		if(i%2) qw[1].pb(x);
		else qw[0].pb(x);
	}
	cout<<mul(f(0),f(1))<<ln;

}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == a[i+2] && a[i] != -1) return 0;
	}
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 != -1){ //左端固定
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp;
					int len = pos2-pos1+1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-1+mod)%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp-1+mod)%mod;
					}
					else{
						tmp = ((1+poww(k-1,len-1,mod))%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp+1)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1){
		if(a[pos1] == -1) ans = (ans*k%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return ans%mod;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == a[i+2] && a[i] != -1) return 0;
	}
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 != -1 && pos1 == pos2 && a[pos1] != -1){
				pos1 = pos2 = i;
				continue;
			}
			if(pos1 != -1){ //左端有值
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp;
					int len = pos2-pos1+1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-1+mod)%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp+1)%mod;
					}
					else{
						tmp = ((1+poww(k-1,len-1,mod))%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp-1+mod)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1 && pos1 != -1){
		if(a[pos1] == -1) ans = (ans*k%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return (ans%mod);
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == a[i+2] && a[i] != -1) return 0;
	}
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 != -1 && pos1 == pos2 && a[pos1] != -1){
				pos1 = pos2 = i;
				continue;
			}
			if(pos1 != -1){ //左端有值
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp = 1;
					int len = pos2-pos1+1;
					// if(len == 1) tmp = k-1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-(ll)1+mod)%mod)*poww(k,mod-2,mod)%mod;
						if(a[pos1] == a[i]) tmp = (tmp+(ll)1)%mod;
					}
					else{
						tmp = (((ll)1+poww(k-1,len-1,mod))%mod)*poww(k,mod-2,mod)%mod;
						if(a[pos1] == a[i]) tmp = (tmp-(ll)1+mod)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1 && pos1 != -1){
		if(a[pos1] == -1) ans = ((ans*k)%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return (ans%mod);
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}
/*
11 20
1 4 3 5 -1 6 3 7 5 9 -1
*/


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 != -1){ //左端固定
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp;
					int len = pos2-pos1+1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-1+mod)%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp-1+mod)%mod;
					}
					else{
						tmp = ((1+poww(k-1,len-1,mod))%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp+1)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1){
		if(a[pos1] == -1) ans = (ans*k%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return ans%mod;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == a[i+2] && a[i] != -1) return 0;
	}
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 != -1 && pos1 == pos2 && a[pos1] != -1){
				pos1 = pos2 = i;
				continue;
			}
			if(pos1 != -1){ //左端有值
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp = 1;
					int len = pos2-pos1+1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-(ll)1+mod)%mod)*poww(k,mod-2,mod)%mod;
						if(a[pos1] == a[pos2]) tmp = (tmp+(ll)1)%mod;
					}
					else{
						tmp = (((ll)1+poww(k-1,len-1,mod))%mod)*poww(k,mod-2,mod)%mod;
						if(a[pos1] == a[pos2]) tmp = (tmp-(ll)1+mod)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1 && pos1 != -1){
		if(a[pos1] == -1) ans = ((ans*k)%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return (ans%mod);
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == a[i+2] && a[i] != -1) return 0;
	}
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 != -1 && pos1 == pos2 && a[pos1] != -1){
				pos1 = pos2 = i;
				continue;
			}
			if(pos1 != -1){ //左端有值
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp = 1;
					int len = pos2-pos1+1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-1+mod)%mod)*poww(k,mod-2,mod)%mod;
						if(a[pos1] == a[pos2]) tmp = (tmp+1)%mod;
					}
					else{
						tmp = ((1+poww(k-1,len-1,mod))%mod)*poww(k,mod-2,mod)%mod;
						if(a[pos1] == a[pos2]) tmp = (tmp-1+mod)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1 && pos1 != -1){
		if(a[pos1] == -1) ans = ((ans*k)%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return (ans%mod);
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == a[i+2] && a[i] != -1) return 0;
	}
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 == pos2 && a[pos1] != -1){
				pos1 = pos2 = i;
				continue;
			}
			if(pos1 != -1){ //左端固定
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp;
					int len = pos2-pos1+1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-1+mod)%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp-1+mod)%mod;
					}
					else{
						tmp = ((1+poww(k-1,len-1,mod))%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp+1)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1 && pos1 != -1){
		if(a[pos1] == -1) ans = (ans*k%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return ans%mod;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const ll mod = 998244353;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N];

ll poww(ll a,ll b,ll p)
{
	ll base = a%p,ans = 1;
	while(b!=0){
		if(b&1) ans = (ans*base)%p;
		base = (base*base)%p;
		b >>= 1;
	}
	return (ans%p);
}

ll calc(ll a1,ll q,ll len){
	ll tmp = (a1*(1-poww(q,len,mod))%mod)*(poww(1-q,mod-2,mod)%mod);
	return (tmp%mod);
}

ll solve(int x){
	ll ans = 1; int pos1 = -1, pos2 = -1;
	for(int i = x; i <= n; i += 2){
		if(a[i] == -1){ //右端未固定
			if(pos1 == -1) pos1 = pos2 = i;
			else pos2++;
		}
		else{ //右端固定
			if(pos1 != -1){ //左端固定
				pos2++;
				if(a[pos1] == -1){ //左端任意
					int len = pos2-pos1+1;
					ans = (ans*poww(k-1,len-1,mod))%mod;
				}
				else{ //左端不任意
					ll tmp;
					int len = pos2-pos1+1;
					if(len%2 == 1){ //奇数
						tmp = ((poww(k-1,len-1,mod)-1)%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp-1+mod)%mod;
					}
					else{
						tmp = ((1+poww(k-1,len-1,mod))%mod)*(poww(k,mod-2,mod)%mod);
						if(a[pos1] == a[pos2]) tmp = (tmp+1)%mod;
					}
					ans = (ans*tmp)%mod;
				}
			}
			pos1 = pos2 = i;
		}
	}
	int len = pos2-pos1+1;
	if(len >= 1){
		if(a[pos1] == -1) ans = (ans*k%mod)*poww(k-1,len-1,mod)%mod;
		else ans = ans*poww(k-1,len-1,mod)%mod;
	}
	return ans%mod;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	rep(i,1,n) scanf("%lld",&a[i]);
	// printf("%lld\n",solve(1));
	// printf("%lld\n",solve(2));
	printf("%lld\n",(solve(1)*solve(2))%mod);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int mod = 998244353;
int dp[maxn][2];
long long qpow(long long a,int b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % mod;
        a = a* a % mod;
        b = b/2;
    }
    return ans;
}
vector<int>O,E;
int n,k;
long long solve(vector<int> &V)
{
    for(int i = 0 ; i < V.size() ; i ++)
    {
        if(V[i] == V[i+1] && V[i] == -1) return 0;
    }
    long long ans = 1;
    for(int i = 0 ; i < V.size() ; i++)
    {
        if(V[i] == -1)
        {
            int r = i , l = i;
            while(r+1 < V.size() && V[r+1] == -1) r++;
            //cout<<l<<"  "<<r<<endl;
            if(r == V.size() - 1 && l == 0) {return k * qpow(k-1,V.size()-1) % mod;} // xxxx
            else if(l == 0 || r == V.size()-1) ans = ans * qpow(k-1,r-l+1) % mod;  // axxxx , xxxxa
            else if(V[l-1] == V[r+1]) ans = ans * dp[r-l+1][1] % mod;
            else if(V[l-1] != V[r+1]) ans = ans * dp[r-l+1][0] % mod;
            i = r;
        }
    }
    return ans;
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
    {
        int t;scanf("%d",&t);
        if(i&1) O.push_back(t);
        else E.push_back(t);
    }
    dp[1][0] = k - 2;
    dp[1][1] = k - 1;
    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = (k-1) * dp[i-1][0] % mod;
        dp[i][0] = (dp[i-1][1] + (k-2) * dp[i-1][0]) % mod;
    }
    long long ans = solve(O) * solve(E) % mod;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int mod = 998244353;
int dp[maxn][2];
long long qpow(long long a,int b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % mod;
        a = a* a % mod;
        b = b/2;
    }
    return ans;
}
vector<int>O,E;
int n,k;
long long solve(vector<int> &V)
{
    for(int i = 0 ; i < V.size() ; i ++)
    {
        if(V[i] == V[i+1] && V[i] != -1) return 0;
    }
    long long ans = 1;
    for(int i = 0 ; i < V.size() ; i++)
    {
        if(V[i] == -1)
        {
            int r = i , l = i;
            while(r+1 < V.size() && V[r+1] == -1) r++;
            if(r == V.size() - 1 && l == 0) {return k * qpow(k-1,V.size()-1) % mod;} // xxxx
            else if(l == 0 || r == V.size()-1) ans = ans * qpow(k-1,r-l+1) % mod;  // axxxx , xxxxa
            else if(V[l-1] == V[r+1]) ans = ans * dp[r-l+1][1] % mod;
            else if(V[l-1] != V[r+1]) ans = ans * dp[r-l+1][0] % mod;
            i = r;
        }
    }
    return ans;
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
    {
        int t;scanf("%d",&t);
        if(i&1) O.push_back(t);
        else E.push_back(t);
    }
    dp[1][0] = k - 2;
    dp[1][1] = k - 1;
    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = (k-1) * dp[i-1][0] % mod;
        dp[i][0] = (dp[i-1][1] + (k-2) * dp[i-1][0] % mod) % mod;
    }
    long long ans = solve(O) * solve(E) % mod;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int mod = 998244353;
long long dp[maxn][2];
long long qpow(long long a,int b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % mod;
        a = a* a % mod;
        b = b/2;
    }
    return ans;
}
vector<int>O,E;
int n,k;
long long solve(vector<int> &V)
{
    for(int i = 0 ; i < V.size() ; i ++)
    {
        if(V[i] == V[i+1] && V[i] != -1) return 0;
    }
    long long ans = 1;
    for(int i = 0 ; i < V.size() ; i++)
    {
        if(V[i] == -1)
        {
            int r = i , l = i;
            while(r+1 < V.size() && V[r+1] == -1) r++;
            if(r == V.size() - 1 && l == 0) {return k * qpow(k-1,V.size()-1) % mod;} // xxxx
            else if(l == 0 || r == V.size()-1) ans = ans * qpow(k-1,r-l+1) % mod;  // axxxx , xxxxa
            else if(V[l-1] == V[r+1]) ans = ans * dp[r-l+1][1] % mod;
            else if(V[l-1] != V[r+1]) ans = ans * dp[r-l+1][0] % mod;
            i = r;
        }
    }
    return ans;
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
    {
        int t;scanf("%d",&t);
        if(i&1) O.push_back(t);
        else E.push_back(t);
    }
    dp[1][0] = k - 2;
    dp[1][1] = k - 1;
    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = (k-1) * dp[i-1][0] % mod;
        dp[i][0] = (dp[i-1][1] + (k-2) * dp[i-1][0] % mod) % mod;
    }
    long long ans = solve(O) * solve(E) % mod;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int mod = 998244353;
int dp[maxn][2];
long long qpow(int a,int b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % mod;
        a = a* a % mod;
        b = b/2;
    }
    return ans;
}
vector<int>O,E;
int n,k;
long long solve(vector<int> &V)
{
    for(int i = 0 ; i < V.size() ; i ++)
    {
        if(V[i] == V[i+1] && V[i] == -1) return 0;
    }
    long long ans = 1;
    for(int i = 0 ; i < V.size() ; i++)
    {
        if(V[i] == -1)
        {
            int r = i , l = i;
            while(r+1 < V.size() && V[r+1] == -1) r++;
            //cout<<l<<"  "<<r<<endl;
            if(r == V.size() - 1 && l == 0) {return k * qpow(k-1,V.size()-1) % mod;} // xxxx
            else if(l == 0 || r == V.size()-1) return qpow(k-1,r-l+1);  // axxxx , xxxxa
            else if(V[l-1] == V[r+1]) ans = ans * dp[r-l+1][1] % mod;
            else if(V[l-1] != V[r+1]) ans = ans * dp[r-l+1][0] % mod;
            i = r;
        }
    }
    return ans;
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
    {
        int t;scanf("%d",&t);
        if(i&1) O.push_back(t);
        else E.push_back(t);
    }
    dp[1][0] = k - 2;
    dp[1][1] = k - 1;
    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = (k-1) * dp[i-1][0] % mod;
        dp[i][0] = dp[i-1][1] + (k-2) * dp[i-1][0] % mod;
    }
    long long ans = solve(O) * solve(E) % mod;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int mod = 998244353;
int dp[maxn][2];
long long qpow(int a,int b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % mod;
        a = a* a % mod;
        b = b/2;
    }
    return ans;
}
vector<int>O,E;
int n,k;
long long solve(vector<int> &V)
{
    for(int i = 0 ; i < V.size() ; i ++)
    {
        if(V[i] == V[i+1] && V[i] == -1) return 0;
    }
    long long ans = 1;
    for(int i = 0 ; i < V.size() ; i++)
    {
        if(V[i] == -1)
        {
            int r = i , l = i;
            while(r+1 < V.size() && V[r+1] == -1) r++;
            if(r == V.size() - 1 && l == 0) {return k * qpow(k-1,n-1) % mod;} // xxxx
            else if(l == 0 || r == V.size()-1) return qpow(k-1,r-l+1);  // axxxx , xxxxa
            else if(V[l-1] == V[r+1]) ans = ans * dp[r-l+1][1] % mod;
            else if(V[l-1] != V[r+1]) ans = ans * dp[r-l+1][0] % mod;
            i = r;
        }
    }
    return ans;
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
    {
        int t;scanf("%d",&t);
        if(i&1) O.push_back(t);
        else E.push_back(t);
    }
    dp[1][0] = k - 2;
    dp[1][1] = k - 1;
    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = (k-1) * dp[i-1][0] % mod;
        dp[i][0] = dp[i-1][1] + (k-2) * dp[i-1][0] % mod;
    }
    long long ans = solve(O) * solve(E) % mod;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int mod = 998244353;
int dp[maxn][2];
long long qpow(long long a,int b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % mod;
        a = a* a % mod;
        b = b/2;
    }
    return ans;
}
vector<int>O,E;
int n,k;
long long solve(vector<int> &V)
{
    for(int i = 0 ; i < V.size() ; i ++)
    {
        if(V[i] == V[i+1] && V[i] != -1) return 0;
    }
    long long ans = 1;
    for(int i = 0 ; i < V.size() ; i++)
    {
        if(V[i] == -1)
        {
            int r = i , l = i;
            while(r+1 < V.size() && V[r+1] == -1) r++;
            //cout<<l<<"  "<<r<<endl;
            if(r == V.size() - 1 && l == 0) {return k * qpow(k-1,V.size()-1) % mod;} // xxxx
            else if(l == 0 || r == V.size()-1) ans = ans * qpow(k-1,r-l+1) % mod;  // axxxx , xxxxa
            else if(V[l-1] == V[r+1]) ans = ans * dp[r-l+1][1] % mod;
            else if(V[l-1] != V[r+1]) ans = ans * dp[r-l+1][0] % mod;
            i = r;
        }
    }
    return ans;
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
    {
        int t;scanf("%d",&t);
        if(i&1) O.push_back(t);
        else E.push_back(t);
    }
    dp[1][0] = k - 2;
    dp[1][1] = k - 1;
    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = (k-1) * dp[i-1][0] % mod;
        dp[i][0] = (dp[i-1][1] + (k-2) * dp[i-1][0]) % mod;
    }
    long long ans = solve(O) * solve(E) % mod;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int mod = 998244353;
int dp[maxn][2];
long long qpow(long long a,int b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % mod;
        a = a* a % mod;
        b = b/2;
    }
    return ans;
}
vector<int>O,E;
int n,k;
long long solve(vector<int> &V)
{
    for(int i = 0 ; i < V.size() ; i ++)
    {
        if(V[i] == V[i+1] && V[i] == -1) return 0;
    }
    long long ans = 1;
    for(int i = 0 ; i < V.size() ; i++)
    {
        if(V[i] == -1)
        {
            int r = i , l = i;
            while(r+1 < V.size() && V[r+1] == -1) r++;
            //cout<<l<<"  "<<r<<endl;
            if(r == V.size() - 1 && l == 0) {return k * qpow(k-1,V.size()-1) % mod;} // xxxx
            else if(l == 0 || r == V.size()-1) return qpow(k-1,r-l+1);  // axxxx , xxxxa
            else if(V[l-1] == V[r+1]) ans = ans * dp[r-l+1][1] % mod;
            else if(V[l-1] != V[r+1]) ans = ans * dp[r-l+1][0] % mod;
            i = r;
        }
    }
    return ans;
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < n ; i++)
    {
        int t;scanf("%d",&t);
        if(i&1) O.push_back(t);
        else E.push_back(t);
    }
    dp[1][0] = k - 2;
    dp[1][1] = k - 1;
    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = (k-1) * dp[i-1][0] % mod;
        dp[i][0] = (dp[i-1][1] + (k-2) * dp[i-1][0]) % mod;
    }
    long long ans = solve(O) * solve(E) % mod;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll solve(ll k, vector<ll> a) {
    int n = a.size();

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 0;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans += k * edge[n - 1];
        else if (p.F == 0 || p.S == n)
            ans += edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans += same[p.S - p.F];
        else
            ans += diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(n / 2);
    diff.resize(n / 2);
    same[1] = k - 1;
    diff[1] = k - 2;
    for (int i = 2; i < n / 2; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> even, odd;
    forn(i, n) {
        if (i & 1)
            odd.push_back(a[i]);
        else
            even.push_back(a[i]);
    }

    cout << solve(k, odd) * solve(k, even) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll ways(ll k, vector<ll>& a) {
    int n = a.size();
    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= k * edge[n - 1] % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));

    same[1] = k - 1;
    diff[1] = k - 2;

    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(max(2LL, n));
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> odds, evens;
    forn(i, n) {
        if (i & 1)
            odds.push_back(a[i]);
        else
            evens.push_back(a[i]);
    }

    cout << ways(k, odds) * ways(k, evens) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll solve(ll k, vector<ll> a) {
    int n = a.size();

    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 0;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans += k * edge[n - 1];
        else if (p.F == 0 || p.S == n)
            ans += edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans += same[p.S - p.F];
        else
            ans += diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));
    same[1] = k - 1;
    diff[1] = k - 2;
    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> even, odd;
    forn(i, n) {
        if (i & 1)
            odd.push_back(a[i]);
        else
            even.push_back(a[i]);
    }

    cout << solve(k, odd) * solve(k, even) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll ways(ll k, vector<ll>& a) {
    int n = a.size();
    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;

            // [l, r) is all -1's
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= edge[n - 1] * k % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    // 2 <= n, k <= 2e5
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));

    same[1] = k - 1;
    diff[1] = k - 2;

    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 1]) % mod;
    }

    edge.resize(max(2LL, n));
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = edge[i - 1] * (k - 1) % mod;

    vector<ll> odds, evens;
    forn(i, n) {
        if (i & 1)
            odds.push_back(a[i]);
        else
            evens.push_back(a[i]);
    }

    cout << ways(k, odds) * ways(k, evens) % mod << endl;

    // same[i]
    // How many ways can we fill i -1's if the boundary items are same
    //
    // diff[i]
    // Boundary items are different
    //
    // edge[i]
    // -1 -1 a or a -1 -1
    //
    // If the entire array is -1
    // k * (k - 1)^(n - 1) mod m
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll non_consec(ll k, vector<ll> a) {
    int n = a.size();

    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= (k * edge[n - 1]) % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));
    same[1] = k - 1;
    diff[1] = k - 2;
    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> even, odd;
    forn(i, n) {
        if (i & 1)
            odd.push_back(a[i]);
        else
            even.push_back(a[i]);
    }

    cout << non_consec(k, odd) * non_consec(k, even) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll ways(ll k, vector<ll>& a) {
    int n = a.size();
    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= edge[n - 1] * k % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));

    same[1] = k - 1;
    diff[1] = k - 2;

    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = edge[i - 1] * (k - 1) % mod;

    vector<ll> odds, evens;
    forn(i, n) {
        if (i & 1)
            odds.push_back(a[i]);
        else
            evens.push_back(a[i]);
    }

    cout << ways(k, odds) * ways(k, evens) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll ways(ll k, vector<ll> a) {
    int n = a.size();
    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= k * edge[n - 1] % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));

    same[1] = k - 1;
    diff[1] = k - 2;

    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> evens, odds;
    forn(i, n) {
        if (i & 1)
            odds.push_back(a[i]);
        else
            evens.push_back(a[i]);
    }

    cout << ways(k, odds) * ways(k, evens) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll ways(ll k, vector<ll>& a) {
    int n = a.size();
    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= k * edge[n - 1] % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));

    same[1] = k - 1;
    diff[1] = k - 2;

    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> odds, evens;
    forn(i, n) {
        if (i & 1)
            odds.push_back(a[i]);
        else
            evens.push_back(a[i]);
    }

    cout << ways(k, odds) * ways(k, evens) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll solve(ll k, vector<ll> a) {
    int n = a.size();

    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= (k * edge[n - 1]) % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));
    same[1] = k - 1;
    diff[1] = k - 2;
    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> even, odd;
    forn(i, n) {
        if (i & 1)
            odd.push_back(a[i]);
        else
            even.push_back(a[i]);
    }

    cout << solve(k, odd) * solve(k, even) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll ways(ll k, vector<ll>& a) {
    int n = a.size();
    forn(i, n - 1)
        if (a[i] != -1 && a[i + 1] != -1 && a[i] == a[i + 1])
            return 0;

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 1;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans *= edge[n - 1] * k % mod;
        else if (p.F == 0 || p.S == n)
            ans *= edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans *= same[p.S - p.F];
        else
            ans *= diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));

    same[1] = k - 1;
    diff[1] = k - 2;

    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 1]) % mod;
    }

    edge.resize(max(2LL, n));
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = edge[i - 1] * (k - 1) % mod;

    vector<ll> odds, evens;
    forn(i, n) {
        if (i & 1)
            odds.push_back(a[i]);
        else
            evens.push_back(a[i]);
    }

    cout << ways(k, odds) * ways(k, evens) % mod << endl;
}


#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;

vector<ll> same, diff, edge;

ll solve(ll k, vector<ll> a) {
    int n = a.size();

    vector<pi> runs;
    for (int l = 0; l < n; ) {
        if (a[l] != -1)
            l++;
        else {
            int r = l + 1;
            while (r < n && a[r] == -1)
                r++;
            runs.emplace_back(l, r);
            l = r;
        }
    }

    ll ans = 0;
    for (pi p : runs) {
        if (p.F == 0 && p.S == n)
            ans += k * edge[n - 1];
        else if (p.F == 0 || p.S == n)
            ans += edge[p.S - p.F];
        else if (a[p.F - 1] == a[p.S])
            ans += same[p.S - p.F];
        else
            ans += diff[p.S - p.F];
        ans %= mod;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    forn(i, n)
        cin >> a[i];

    same.resize(max(2LL, n));
    diff.resize(max(2LL, n));
    same[1] = k - 1;
    diff[1] = k - 2;
    for (int i = 2; i < n; i++) {
        same[i] = (k - 1) * diff[i - 1] % mod;
        diff[i] = (same[i - 1] + (k - 2) * diff[i - 2]) % mod;
    }

    edge.resize(n);
    edge[0] = 1;
    for (int i = 1; i < n; i++)
        edge[i] = (k - 1) * edge[i - 1] % mod;

    vector<ll> even, odd;
    forn(i, n) {
        if (i & 1)
            odd.push_back(a[i]);
        else
            even.push_back(a[i]);
    }

    cout << solve(k, odd) * solve(k, even) % mod << endl;
}


#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<math.h>
#include<random>
#include<queue>
#include<tuple>
#include<stack>
#include<string>
#include<iomanip>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pp;
typedef tuple<int, int, int> tt;

#define Go_Go_Power_Rangers ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const ll mod = 998244353;
const int inf = 1000000000;
const int MAXL = 500;

ll poW(ll a, ll b) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll t = poW(a, b / 2);
		return (t*t) % mod;
	}
	else {
		ll t = poW(a, (b - 1) / 2);
		t = (t*t) % mod;
		return (t*a) % mod;
	}
}

int main() {

	Go_Go_Power_Rangers;

	int n, k;
	cin >> n >> k;
	vector<int> a, b;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (i % 2 == 0)
			a.push_back(x);
		else
			b.push_back(x);
	}

	ll ans = 0;

	ll res = 0;

	vector<ll> f(n + 1);
	f[1] = 0;
	ll t = k - 1;
	for (int i = 2; i <= n; i++) {
		t = (t*(k - 1)) % mod;
		f[i] = t - f[i - 1];
	}

	int m = a.size();

	int pre = -1;
	int cnt = 0;

	res = 1;

	for (int i = 0; i < m; i++) {
		if (a[i] == -1)
			cnt++;
		else {
			if (cnt == 0) {
				res = pre == a[i] ? 0 : res;
			}
			else {
				if (pre != -1) {
					ll x = (pre == a[i] || pre == -1) ? k - 1 : k - 2;
					if (cnt % 2 == 0)
						x = -x;
					x = (x + mod + f[cnt]) % mod;
					res = (res*x) % mod;
				}
				else {
					ll x = poW(k - 1, cnt);
					res = (res*x) % mod;
				}
				cnt = 0;
			}
			pre = a[i];
		}
	}

	if (cnt != 0) {
		ll y = pre == -1 ? k : k - 1;
		for (int i = 1; i < cnt; i++)
			y = (y*(k - 1)) % mod;
		res = (res * y) % mod;
	}

	m = b.size();

	pre = -1;
	cnt = 0;

	ans = res;
	res = 1;

	for (int i = 0; i < m; i++) {
		if (b[i] == -1)
			cnt++;
		else {
			if (cnt == 0) {
				res = pre==b[i] ? 0 : res;
			}
			else {
				if (pre != -1) {
					ll x = (pre == b[i] || pre == -1) ? k - 1 : k - 2;
					if (cnt % 2 == 0)
						x = -x;
					x = (x + mod + f[cnt]) % mod;
					res = (res*x) % mod;
				}
				else {
					ll x = poW(k - 1, cnt);
					res = (res*x) % mod;
				}
				cnt = 0;
			}
			pre = b[i];
		}
	}

	if (cnt != 0) {
		ll z = pre == -1 ? k : k - 1;
		for (int i = 1; i < cnt; i++)
			z = (z*(k - 1)) % mod;
		res = (res * z) % mod;
	}

	ans = (ans*res) % mod;
	cout << ans;

	return 0;
}

//9 3
//-1 - 1 - 1 - 1 1 2 3 - 1 - 1
//-1 -1 1 3 -1
//-1 -1 2 -1