#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, m, bad[41][41], dp[1 << 20];
map <string, int> mp;
vector <int> a;

int idx(string s){
    if(mp.find(s) == mp.end())
        mp[s] = mp.size() - 1;
    return mp[s];
}
void go(int mask){
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if(i != j && (mask & (1LL << i)) && (mask & (1LL << j)))
                bad[i][j] = 1;
}
bool valid(int mask){
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if((mask & (1LL << i)) && (mask & (1LL << j)) && bad[i][j])
                return 0;
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    ll mask = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        if(x == 1){
            go(mask);
            mask = 0;
        }
        else{
            string s;
            cin >> s;
            mask |= (1LL << idx(s));
        }
    }
    go(mask);
    int l = m / 2;
    int r = m - l;
    int ans = 0;
    for(int i = 1 ; i < (1 << l) ; i++){
        if(valid(i)) dp[i] = __builtin_popcount(i);
        else{
            for(int j = 0 ; j < l ; j++){
                if((i & (1 << j)) == 0) continue;
                dp[i] = max(dp[i], dp[i ^ (1 << j)]);
            }
        }
        ans = max(ans, dp[i]);
    }
    for(int i = 0 ; i < (1 << r) ; i++){
        if(!valid(i)) continue;
        int mask = 0;
        for(int j = 0 ; j < l ; j++){
            int ok = 1;
            for(int k = 0 ; k < r ; k++){
                if(((1 << k) & i) == 0) continue;
                if(bad[j][k + l]) ok = 0;
            }
            if(ok == 1) mask |= (1 << j);
        }
        ans = max(ans, __builtin_popcount(i) + dp[mask]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, m, bad[41][41], dp[1 << 20];
map <string, int> mp;
vector <int> a;

int idx(string s){
    if(mp.find(s) == mp.end())
        mp[s] = mp.size() - 1;
    return mp[s];
}
void go(int mask){
    cout << "mask: " << mask << endl;
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if(i != j && (mask & (1LL << i)) && (mask & (1 << j)))
                bad[i][j] = 1;
}
bool valid(int mask){
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if((mask & (1LL << i)) && (mask & (1LL << j)) && bad[i][j])
                return 0;
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    ll mask = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        if(x == 1){
            go(mask);
            mask = 0;
        }
        else{
            string s;
            cin >> s;
            mask |= (1LL << idx(s));
        }
    }
    go(mask);
    int l = m / 2;
    int r = m - l;
    int ans = 0;
    for(int i = 1 ; i < (1 << l) ; i++){
        if(valid(i)) dp[i] = __builtin_popcount(i);
        else{
            for(int j = 0 ; j < l ; j++){
                if((i & (1 << j)) == 0) continue;
                dp[i] = max(dp[i], dp[i ^ (1 << j)]);
            }
        }
        ans = max(ans, dp[i]);
    }
    for(int i = 0 ; i < (1 << r) ; i++){
        if(!valid(i)) continue;
        int mask = 0;
        for(int j = 0 ; j < l ; j++){
            int ok = 1;
            for(int k = 0 ; k < r ; k++){
                if(((1 << k) & i) == 0) continue;
                if(bad[j][k + l]) ok = 0;
            }
            if(ok == 1) mask |= (1 << j);
        }
        ans = max(ans, __builtin_popcount(i) + dp[mask]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, m, bad[41][41], dp[1 << 20];
map <string, int> mp;
vector <int> a;

int idx(string s){
    if(mp.find(s) == mp.end())
        mp[s] = mp.size() - 1;
    return mp[s];
}
void go(int mask){
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if(i != j && (mask & (1LL << i)) && (mask & (1 << j)))
                bad[i][j] = 1;
}
bool valid(int mask){
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if((mask & (1LL << i)) && (mask & (1LL << j)) && bad[i][j])
                return 0;
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    ll mask = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        if(x == 1){
            go(mask);
            mask = 0;
        }
        else{
            string s;
            cin >> s;
            mask |= (1LL << idx(s));
        }
    }
    go(mask);
    int l = m / 2;
    int r = m - l;
    int ans = 0;
    for(int i = 1 ; i < (1 << l) ; i++){
        if(valid(i)) dp[i] = __builtin_popcount(i);
        else{
            for(int j = 0 ; j < l ; j++){
                if((i & (1 << j)) == 0) continue;
                dp[i] = max(dp[i], dp[i ^ (1 << j)]);
            }
        }
        ans = max(ans, dp[i]);
    }
    for(int i = 0 ; i < (1 << r) ; i++){
        if(!valid(i)) continue;
        int mask = 0;
        for(int j = 0 ; j < l ; j++){
            int ok = 1;
            for(int k = 0 ; k < r ; k++){
                if(((1 << k) & i) == 0) continue;
                if(bad[j][k + l]) ok = 0;
            }
            if(ok == 1) mask |= (1 << j);
        }
        ans = max(ans, __builtin_popcount(i) + dp[mask]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll n, m, dp[1LL << 20];
bool valid[1LL << 20][2];
ll bad[41];
map <string, ll> mp;

ll idx(string s){
    if(mp.find(s) == mp.end()){
        ll sz = mp.size();
        mp[s] = sz;
    }
    return mp[s];
}
void go(ll mask){
    for(ll i = 0 ; i < m ; i++)
        for(ll j = 0 ; j < m ; j++)
            if(i != j && (mask & (1LL << i)) && (mask & (1LL << j)))
                bad[i] |= (1LL << j);
}
bool good(ll x, ll y){
    return !(bad[x] & (1LL << y));
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    ll mask = 0;
    for(ll i = 0 ; i < n ; i++){
        ll x;
        cin >> x;
        if(x == 1){
            go(mask);
            mask = 0;
        }
        else{
            string s;
            cin >> s;
            mask |= (1LL << idx(s));
        }
    }
    go(mask);
    ll l = m / 2;
    ll r = m - l;
    valid[0][0] = 1;
    for(ll i = 1 ; i < (1LL << l) ; i++){
        ll cur = -1;
        for(ll j = 0 ; j < l ; j++){
            if(((1LL << j) & i) == 0) continue;
            if(valid[i ^ (1LL << j)][0]) cur = j;
        }
        if(cur == -1) continue;
        ll ok = 1;
        for(ll j = 0 ; j < l ; j++){
            if(((1LL << j) & i) == 0) continue;
            if(j == cur) continue;
            if(!good(cur, j)) ok = 0;
        }
        if(ok) valid[i][0] = 1;
    }
    valid[0][1] = 1;
    for(ll i = 1 ; i < (1LL << r) ; i++){
        ll cur = -1;
        for(ll j = 0 ; j < r ; j++){
            if(((1LL << j) & i) == 0) continue;
            if(valid[i ^ (1LL << j)][1]) cur = j;
        }
        if(cur == -1) continue;
        ll ok = 1;
        for(ll j = 0 ; j < r ; j++){
            if(((1LL << j) & i) == 0) continue;
            if(j == cur) continue;
            if(!good(cur + l, j + l)) ok = 0;
        }
        if(ok) valid[i][1] = 1;
    }
    ll ans = 0;
    for(ll i = 1 ; i < (1LL << l) ; i++){
        if(valid[i][0]) dp[i] = __builtin_popcount(i);
        else{
            for(ll j = 0 ; j < l ; j++){
                if((i & (1LL << j)) == 0) continue;
                dp[i] = max(dp[i], dp[i ^ (1LL << j)]);
            }
        }
        ans = max(ans, dp[i]);
    }
    for(ll i = 0 ; i < (1LL << r) ; i++){
        if(!valid[i][1]) continue;
        ll mask = 0;
        for(ll j = 0 ; j < l ; j++){
            if(bad[j] & (i << l)) continue;
            mask |= (1LL << j);
        }
        ans = max(ans, __builtin_popcount(i) + dp[mask]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, m, bad[41][41], dp[1 << 20];
map <string, int> mp;
vector <int> a;

int idx(string s){
    if(mp.find(s) == mp.end()){
        int sz = mp.size();
        mp[s] = sz;
    }
    return mp[s];
}
void go(int mask){
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if(i != j && (mask & (1LL << i)) && (mask & (1LL << j)))
                bad[i][j] = 1;
}
bool valid(int mask, int inc){
    for(int i = 0 ; i < m ; i++)
        for(int j = 0 ; j < m ; j++)
            if((mask & (1LL << i)) && (mask & (1LL << j)) && bad[i + inc][j + inc])
                return 0;
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    ll mask = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        if(x == 1){
            go(mask);
            mask = 0;
        }
        else{
            string s;
            cin >> s;
            mask |= (1LL << idx(s));
        }
    }
    go(mask);
    int l = m / 2;
    int r = m - l;
    int ans = 0;
    for(int i = 1 ; i < (1 << l) ; i++){
        if(valid(i, 0)) dp[i] = __builtin_popcount(i);
        else{
            for(int j = 0 ; j < l ; j++){
                if((i & (1 << j)) == 0) continue;
                dp[i] = max(dp[i], dp[i ^ (1 << j)]);
            }
        }
        ans = max(ans, dp[i]);
    }
    for(int i = 0 ; i < (1 << r) ; i++){
        if(!valid(i, l)) continue;
        int mask = 0;
        for(int j = 0 ; j < l ; j++){
            int ok = 1;
            for(int k = 0 ; k < r ; k++){
                if(((1 << k) & i) == 0) continue;
                if(bad[j][k + l]) ok = 0;
            }
            if(ok == 1) mask |= (1 << j);
        }
        ans = max(ans, __builtin_popcount(i) + dp[mask]);
    }
    cout << ans << endl;
}


#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
const ll inf = (ll)2e15;
ll n,k;
void not_correct(){
	cout << "Incorrect sequence\n";
	exit(0);
}
void fill(vector<ll> &arr, ll l, ll r){
	if(l+1>=r)
		return;
	if(arr[l]>=0&&arr[r]>=0){
		arr[l+1]=arr[l]+1;
		fill(arr,l+1,r);
		return;
	}
	if(arr[l]<=0&&arr[r]<=0){
		arr[r-1]=arr[r]-1;
		fill(arr,l,r-1);
		return;
	}
	ll m = (l+r)/2;
	arr[m]=0;
	arr[m]=max(arr[m],arr[l]+m-l);
	arr[m]=min(arr[m],arr[r]+r-m);
	fill(arr,l,m);
	fill(arr,m,r);
}
void opt(vector<ll> &arr){
	// check if correct at all
	arr.insert(arr.begin(),-inf);
	arr.push_back(inf+1);

	vector<ll> copy = arr;
	ll m = arr.size();
	for(ll i = m-2; i >= 0; --i){
		if(copy[i]==inf)
			copy[i]=copy[i+1]-1;
		if(copy[i]>=copy[i+1])
			not_correct();
	}
	// it's correct, build it
	vector<ll> placed;
	for(ll i = 0; i < m; ++i)
		if(arr[i]!=inf)
			placed.push_back(i);
	for(ll i = 0; i < placed.size()-1; ++i)
		fill(arr,placed[i],placed[i+1]);

	arr.erase(arr.begin());
	arr.pop_back();
}
int main(){
	cin >> n >> k;
	vector<ll> input(n);
	for(ll i = 0; i < n; ++i){
		string cur;
		cin >> cur;
		if(cur=="?")
			input[i]=inf;
		else{
			stringstream in(cur.c_str());
			in >> input[i];
		}
	}
	// separate into k disconnected pieces
	// optimize each one separately
	vector<vector<ll> > sep(min(n,k));
	for(ll i = 0; i < min(n,k); ++i){
		for(ll j = i; j < n; j+=k){
			sep[i].push_back(input[j]);
		}
		opt(sep[i]);
	}
	for(ll i = 0; i < sep.size(); ++i){
		for(ll j = 0; j < sep[i].size(); ++j){
			input[i+j*k]=sep[i][j];
		}
	}
	for(ll i = 0; i < n; ++i)
		cout << input[i] << " \n"[i==n-1];
}


#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
using namespace std;
const int inf = 2e9;
int n,k;
void not_correct(){
	cout << "Incorrect sequence\n";
	exit(0);
}
/*
int sum(vector<int> &arr){
	int ans = 0;
	for(int i = 0; i < n; ++i){
		ans+=abs(arr[i]);
	}
	return ans;
}
*/
void fill(vector<int> &arr, int l, int r){
	if(l+1==r)
		return;
	if(arr[l]>0&&arr[r]>0){
		arr[l+1]=arr[l]+1;
		fill(arr,l+1,r);
		return;
	}
	if(arr[l]<0&&arr[r]<0){
		arr[r-1]=arr[r]-1;
		fill(arr,l,r-1);
		return;
	}
	int m = (l+r)/2;
	arr[m]=0;
	fill(arr,l,m);
	fill(arr,m,r);
}
void opt(vector<int> &arr){
	// check if correct at all
	arr.insert(arr.begin(),-inf);
	arr.push_back(inf);

	vector<int> copy = arr;
	int m = arr.size();
	for(int i = m-2; i >= 0; --i){
		if(copy[i]==inf)
			copy[i]=copy[i+1]-1;
		if(copy[i]>=copy[i+1])
			not_correct();
	}
	// it's correct, build it
	vector<int> placed;
	for(int i = 0; i < n; ++i)
		if(arr[i]!=inf)
			placed.push_back(i);
	for(int i = 0; i < placed.size()-1; ++i)
		fill(arr,placed[i],placed[i+1]);

	arr.erase(arr.begin());
	arr.pop_back();
}
int main(){
	cin >> n >> k;
	vector<int> input(n);
	for(int i = 0; i < n; ++i){
		string cur;
		cin >> cur;
		if(cur=="?")
			input[i]=inf;
		else{
			stringstream in(cur.c_str());
			in >> input[i];
		}
	}
	// separate into k disconnected pieces
	// optimize each one separately
	vector<vector<int> > sep(min(n,k));
	for(int i = 0; i < min(n,k); ++i){
		for(int j = i; j < n; j+=k){
			sep[i].push_back(input[j]);
		}
		opt(sep[i]);
	}
	for(int i = 0; i < sep.size(); ++i){
		for(int j = 0; j < sep[i].size(); ++j){
			input[i+j*k]=sep[i][j];
		}
	}
	for(int i = 0; i < n; ++i)
		cout << input[i] << " \n"[i==n-1];
}


#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
const ll inf = (ll)2e15;
ll n,k;
void not_correct(){
	cout << "Incorrect sequence\n";
	exit(0);
}
/*
ll sum(vector<ll> &arr){
	ll ans = 0;
	for(ll i = 0; i < n; ++i){
		ans+=abs(arr[i]);
	}
	return ans;
}
*/
void fill(vector<ll> &arr, ll l, ll r){
	//cout << l << ' ' << r << ' ' << arr[l] << ' ' << arr[r] << '\n';
	if(l+1==r)
		return;
	if(arr[l]>=0&&arr[r]>=0){
		arr[l+1]=arr[l]+1;
		fill(arr,l+1,r);
		return;
	}
	if(arr[l]<=0&&arr[r]<=0){
		arr[r-1]=arr[r]-1;
		fill(arr,l,r-1);
		return;
	}
	ll m = (l+r)/2;
	arr[m]=0;
	arr[m]=max(arr[m],arr[l]+m-l);
	arr[m]=min(arr[m],arr[r]+r-m);
	fill(arr,l,m);
	fill(arr,m,r);
}
void opt(vector<ll> &arr){
	// check if correct at all
	arr.insert(arr.begin(),-inf);
	arr.push_back(inf+1);

	vector<ll> copy = arr;
	ll m = arr.size();
	for(ll i = m-2; i >= 0; --i){
		if(copy[i]==inf)
			copy[i]=copy[i+1]-1;
		if(copy[i]>=copy[i+1])
			not_correct();
	}
	// it's correct, build it
	vector<ll> placed;
	for(ll i = 0; i < m; ++i)
		if(arr[i]!=inf)
			placed.push_back(i);
	for(ll i = 0; i < placed.size()-1; ++i)
		fill(arr,placed[i],placed[i+1]);

	arr.erase(arr.begin());
	arr.pop_back();
}
int main(){
	cin >> n >> k;
	vector<ll> input(n);
	for(ll i = 0; i < n; ++i){
		string cur;
		cin >> cur;
		if(cur=="?")
			input[i]=inf;
		else{
			stringstream in(cur.c_str());
			in >> input[i];
		}
	}
	// separate into k disconnected pieces
	// optimize each one separately
	vector<vector<ll> > sep(min(n,k));
	for(ll i = 0; i < min(n,k); ++i){
		for(ll j = i; j < n; j+=k){
			sep[i].push_back(input[j]);
		}
		opt(sep[i]);
	}
	for(ll i = 0; i < sep.size(); ++i){
		for(ll j = 0; j < sep[i].size(); ++j){
			input[i+j*k]=sep[i][j];
		}
	}
	for(ll i = 0; i < n; ++i)
		cout << input[i] << " \n"[i==n-1];
}


#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
const ll inf = 2e9;
ll n,k;
void not_correct(){
	cout << "Incorrect sequence\n";
	exit(0);
}
/*
ll sum(vector<ll> &arr){
	ll ans = 0;
	for(ll i = 0; i < n; ++i){
		ans+=abs(arr[i]);
	}
	return ans;
}
*/
void fill(vector<ll> &arr, ll l, ll r){
	if(l+1==r)
		return;
	if(arr[l]>0&&arr[r]>0){
		arr[l+1]=arr[l]+1;
		fill(arr,l+1,r);
		return;
	}
	if(arr[l]<0&&arr[r]<0){
		arr[r-1]=arr[r]-1;
		fill(arr,l,r-1);
		return;
	}
	ll m = (l+r)/2;
	arr[m]=0;
	fill(arr,l,m);
	fill(arr,m,r);
}
void opt(vector<ll> &arr){
	// check if correct at all
	arr.insert(arr.begin(),-inf);
	arr.push_back(inf);

	vector<ll> copy = arr;
	ll m = arr.size();
	for(ll i = m-2; i >= 0; --i){
		if(copy[i]==inf)
			copy[i]=copy[i+1]-1;
		if(copy[i]>=copy[i+1])
			not_correct();
	}
	// it's correct, build it
	vector<ll> placed;
	for(ll i = 0; i < n; ++i)
		if(arr[i]!=inf)
			placed.push_back(i);
	for(ll i = 0; i < placed.size()-1; ++i)
		fill(arr,placed[i],placed[i+1]);

	arr.erase(arr.begin());
	arr.pop_back();
}
int main(){
	cin >> n >> k;
	vector<ll> input(n);
	for(ll i = 0; i < n; ++i){
		string cur;
		cin >> cur;
		if(cur=="?")
			input[i]=inf;
		else{
			stringstream in(cur.c_str());
			in >> input[i];
		}
	}
	// separate llo k disconnected pieces
	// optimize each one separately
	vector<vector<ll> > sep(min(n,k));
	for(ll i = 0; i < min(n,k); ++i){
		for(ll j = i; j < n; j+=k){
			sep[i].push_back(input[j]);
		}
		opt(sep[i]);
	}
	for(ll i = 0; i < sep.size(); ++i){
		for(ll j = 0; j < sep[i].size(); ++j){
			input[i+j*k]=sep[i][j];
		}
	}
	for(ll i = 0; i < n; ++i)
		cout << input[i] << " \n"[i==n-1];
}


#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
const ll inf = (ll)2e15;
ll n,k;
void not_correct(){
	cout << "Incorrect sequence\n";
	exit(0);
}
/*
ll sum(vector<ll> &arr){
	ll ans = 0;
	for(ll i = 0; i < n; ++i){
		ans+=abs(arr[i]);
	}
	return ans;
}
*/
void fill(vector<ll> &arr, ll l, ll r){
	if(l+1==r)
		return;
	if(arr[l]>0&&arr[r]>0){
		arr[l+1]=arr[l]+1;
		fill(arr,l+1,r);
		return;
	}
	if(arr[l]<0&&arr[r]<0){
		arr[r-1]=arr[r]-1;
		fill(arr,l,r-1);
		return;
	}
	ll m = (l+r)/2;
	arr[m]=0;
	fill(arr,l,m);
	fill(arr,m,r);
}
void opt(vector<ll> &arr){
	// check if correct at all
	arr.insert(arr.begin(),-inf);
	arr.push_back(inf+1);

	vector<ll> copy = arr;
	ll m = arr.size();
	for(ll i = m-2; i >= 0; --i){
		if(copy[i]==inf)
			copy[i]=copy[i+1]-1;
		if(copy[i]>=copy[i+1])
			not_correct();
	}
	// it's correct, build it
	vector<ll> placed;
	for(ll i = 0; i < n; ++i)
		if(arr[i]!=inf)
			placed.push_back(i);
	for(ll i = 0; i < placed.size()-1; ++i)
		fill(arr,placed[i],placed[i+1]);

	arr.erase(arr.begin());
	arr.pop_back();
}
int main(){
	cin >> n >> k;
	vector<ll> input(n);
	for(ll i = 0; i < n; ++i){
		string cur;
		cin >> cur;
		if(cur=="?")
			input[i]=inf;
		else{
			stringstream in(cur.c_str());
			in >> input[i];
		}
	}
	// separate llo k disconnected pieces
	// optimize each one separately
	vector<vector<ll> > sep(min(n,k));
	for(ll i = 0; i < min(n,k); ++i){
		for(ll j = i; j < n; j+=k){
			sep[i].push_back(input[j]);
		}
		opt(sep[i]);
	}
	for(ll i = 0; i < sep.size(); ++i){
		for(ll j = 0; j < sep[i].size(); ++j){
			input[i+j*k]=sep[i][j];
		}
	}
	for(ll i = 0; i < n; ++i)
		cout << input[i] << " \n"[i==n-1];
}


#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
const ll inf = (ll)2e15;
ll n,k;
void not_correct(){
	cout << "Incorrect sequence\n";
	exit(0);
}
void fill(vector<ll> &arr, ll l, ll r){
	if(l+1>=r)
		return;
	if(arr[l]>=0&&arr[r]>=0){
		arr[l+1]=arr[l]+1;
		fill(arr,l+1,r);
		return;
	}
	if(arr[l]<=0&&arr[r]<=0){
		arr[r-1]=arr[r]-1;
		fill(arr,l,r-1);
		return;
	}
	ll m = (l+r)/2;
	arr[m]=0;
	arr[m]=max(arr[m],arr[l]+m-l);
	arr[m]=min(arr[m],arr[r]+m-r);
	fill(arr,l,m);
	fill(arr,m,r);
}
void opt(vector<ll> &arr){
	// check if correct at all
	arr.insert(arr.begin(),-inf);
	arr.push_back(inf+1);

	vector<ll> copy = arr;
	ll m = arr.size();
	for(ll i = m-2; i >= 0; --i){
		if(copy[i]==inf)
			copy[i]=copy[i+1]-1;
		if(copy[i]>=copy[i+1])
			not_correct();
	}
	// it's correct, build it
	vector<ll> placed;
	for(ll i = 0; i < m; ++i)
		if(arr[i]!=inf)
			placed.push_back(i);
	for(ll i = 0; i < placed.size()-1; ++i)
		fill(arr,placed[i],placed[i+1]);

	arr.erase(arr.begin());
	arr.pop_back();
}
int main(){
	cin >> n >> k;
	vector<ll> input(n);
	for(ll i = 0; i < n; ++i){
		string cur;
		cin >> cur;
		if(cur=="?")
			input[i]=inf;
		else{
			stringstream in(cur.c_str());
			in >> input[i];
		}
	}
	// separate into k disconnected pieces
	// optimize each one separately
	vector<vector<ll> > sep(min(n,k));
	for(ll i = 0; i < min(n,k); ++i){
		for(ll j = i; j < n; j+=k){
			sep[i].push_back(input[j]);
		}
		opt(sep[i]);
	}
	for(ll i = 0; i < sep.size(); ++i){
		for(ll j = 0; j < sep[i].size(); ++j){
			input[i+j*k]=sep[i][j];
		}
	}
	for(ll i = 0; i < n; ++i)
		cout << input[i] << " \n"[i==n-1];
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define vi vector<int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define bg(a,n) for(int i=1;i<=(n);printf("%d%s",a[i],i==n?"\n":" "),i++)
using namespace std;
typedef long long LL;
const int inf=1e9;

int n,k;
int a[100001];
int lb[100001],ub[100001];
char temp[100];
vi buc[100001];
void cl(vi x) {
	int l=-1,r=x.size();
	for (int i=0;i<x.size();i++)
		if (a[x[i]]==inf+1) {
			if (lb[x[i]]<=0&&ub[x[i]]>=0) l=i;
			else if (l!=-1&&r==x.size()) r=i;
		}
	if (l!=-1) {
		if (r==x.size()) r--;
		int mid=l+r>>1;
		a[x[mid]]=0;
		for (int i=mid+1;i<x.size();i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i-1]]+1;
		for (int i=mid-1;~i;i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i+1]]-1;
	}
	else {
		for (int i=0;i<x.size();i++)
			if (a[x[i]]==inf+1)
				if (lb[x[i]]>0)
					a[x[i]]=a[x[i-1]]+1;
		for (int i=x.size()-1;~i;i--)
			if (a[x[i]]==inf+1)
				if (ub[x[i]]<0)
					a[x[i]]=a[x[i+1]]-1;
	}
}
bool solve() {
	for (int i=k+1;i<=n;i++)
		if (a[i]==inf+1) {
			if (a[i-k]==inf+1) lb[i]=lb[i-k]+1;
			else lb[i]=a[i-k]+1;
		}
	for (int i=n-k;i;i--)
		if (a[i]==inf+1) {
			if (a[i+k]==inf+1) ub[i]=ub[i+k]-1;
			else ub[i]=a[i+k]-1;
		}
	for (int i=1;i<=n;i++)
		if (a[i]==inf+1) {
			if (lb[i]>ub[i]) return 0;
		}
		else {
			if (i>k)
				if (a[i-k]==inf+1) {
					if (lb[i-k]>=a[i]) return 0;
				}
				else if (a[i]<=a[i-k]) return 0;
			if (i+k<=n)
				if (a[i+k]==inf+1) {
					if (ub[i+k]<=a[i]) return 0;
				}
				//else if (a[i]>=a[i+k]) return 0;
		}
	for (int i=1;i<=n;i++)
		buc[(i-1)%k+1].pb(i);
	for (int i=1;i<=k;i++) cl(buc[i]);
	return 1;
}
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) {
		scanf("%s",temp);
		if (temp[0]=='?') lb[i]=-inf,ub[i]=inf,a[i]=inf+1;
		else a[i]=atoi(temp);
	}
	if (!solve()) puts("Incorrect sequence");
	else for (int i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' ');
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define vi vector<int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define bg(a,n) for(int i=1;i<=(n);printf("%d%s",a[i],i==n?"\n":" "),i++)
using namespace std;
typedef long long LL;
const int inf=1e9*2;

int n,k;
int a[100001];
int lb[100001],ub[100001];
char temp[100];
vi buc[100001];
void cl(vi x) {
	int l=-1,r=x.size(),mid=-1;
	for (int i=0;i<x.size();i++)
		if (a[x[i]]==inf+1)
			if (lb[x[i]]<=0&&ub[x[i]]>=0) { mid=i; break; }
	if (mid!=-1) {
		l=r=mid;
		while (l>0&&a[x[l-1]]==inf+1) l--;
		while (r<x.size()-1&&a[x[r+1]]==inf+1) r++;
		mid=l+r>>1;
		while (!(lb[x[mid]]<=0&&ub[x[mid]]>=0)) mid+=ub[x[mid]]<0?1:-1;

		a[x[mid]]=0;
		for (int i=mid+1;i<x.size();i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i-1]]+1;
		for (int i=mid-1;~i;i--)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i+1]]-1;
	}
	else {
		for (int i=0;i<x.size();i++)
			if (a[x[i]]==inf+1)
				if (lb[x[i]]>0)
					a[x[i]]=a[x[i-1]]+1;
		for (int i=x.size()-1;~i;i--)
			if (a[x[i]]==inf+1)
				if (ub[x[i]]<0)
					a[x[i]]=a[x[i+1]]-1;
	}
}
bool solve() {
	for (int i=k+1;i<=n;i++)
		if (a[i]==inf+1) {
			if (a[i-k]==inf+1) lb[i]=lb[i-k]+1;
			else lb[i]=a[i-k]+1;
		}
	for (int i=n-k;i;i--)
		if (a[i]==inf+1) {
			if (a[i+k]==inf+1) ub[i]=ub[i+k]-1;
			else ub[i]=a[i+k]-1;
		}
	for (int i=1;i<=n;i++)
		if (a[i]==inf+1) {
			if (lb[i]>ub[i]) return 0;
		}
		else {
			if (i>k)
				if (a[i-k]==inf+1) {
					if (lb[i-k]>=a[i]) return 0;
				}
				else if (a[i]<=a[i-k]) return 0;
			if (i+k<=n)
				if (a[i+k]==inf+1) {
					if (ub[i+k]<=a[i]) return 0;
				}
				//else if (a[i]>=a[i+k]) return 0;
		}
	for (int i=1;i<=n;i++)
		buc[(i-1)%k+1].pb(i);
	for (int i=1;i<=k;i++) cl(buc[i]);
	return 1;
}
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) {
		scanf("%s",temp);
		if (temp[0]=='?') lb[i]=-inf,ub[i]=inf,a[i]=inf+1;
		else a[i]=atoi(temp);
	}
	if (!solve()) puts("Incorrect sequence");
	else for (int i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' ');
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define vi vector<int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define bg(a,n) for(int i=1;i<=(n);printf("%d%s",a[i],i==n?"\n":" "),i++)
using namespace std;
typedef long long LL;
const int inf=1e9*2;

int n,k;
int a[100001];
int lb[100001],ub[100001];
char temp[100];
vi buc[100001];
void cl(vi x) {
	int l=-1,r=x.size();
	for (int i=0;i<x.size();i++)
		if (a[x[i]]==inf+1) {
			if (lb[x[i]]<=0&&ub[x[i]]>=0) { if (l==-1) l=i; }
			else if (l!=-1&&r==x.size()) r=i;
		}
	if (l!=-1) {
		if (r==x.size()) r--;
		int mid=l+r>>1;
		a[x[mid]]=0;
		for (int i=mid+1;i<x.size();i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i-1]]+1;
		for (int i=mid-1;~i;i--)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i+1]]-1;
	}
	else {
		for (int i=0;i<x.size();i++)
			if (a[x[i]]==inf+1)
				if (lb[x[i]]>0)
					a[x[i]]=a[x[i-1]]+1;
		for (int i=x.size()-1;~i;i--)
			if (a[x[i]]==inf+1)
				if (ub[x[i]]<0)
					a[x[i]]=a[x[i+1]]-1;
	}
}
bool solve() {
	for (int i=k+1;i<=n;i++)
		if (a[i]==inf+1) {
			if (a[i-k]==inf+1) lb[i]=lb[i-k]+1;
			else lb[i]=a[i-k]+1;
		}
	for (int i=n-k;i;i--)
		if (a[i]==inf+1) {
			if (a[i+k]==inf+1) ub[i]=ub[i+k]-1;
			else ub[i]=a[i+k]-1;
		}
	for (int i=1;i<=n;i++)
		if (a[i]==inf+1) {
			if (lb[i]>ub[i]) return 0;
		}
		else {
			if (i>k)
				if (a[i-k]==inf+1) {
					if (lb[i-k]>=a[i]) return 0;
				}
				else if (a[i]<=a[i-k]) return 0;
			if (i+k<=n)
				if (a[i+k]==inf+1) {
					if (ub[i+k]<=a[i]) return 0;
				}
				//else if (a[i]>=a[i+k]) return 0;
		}
	for (int i=1;i<=n;i++)
		buc[(i-1)%k+1].pb(i);
	for (int i=1;i<=k;i++) cl(buc[i]);
	return 1;
}
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) {
		scanf("%s",temp);
		if (temp[0]=='?') lb[i]=-inf,ub[i]=inf,a[i]=inf+1;
		else a[i]=atoi(temp);
	}
	if (!solve()) puts("Incorrect sequence");
	else for (int i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' ');
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define vi vector<int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define bg(a,n) for(int i=1;i<=(n);printf("%d%s",a[i],i==n?"\n":" "),i++)
using namespace std;
typedef long long LL;
const int inf=1e9;

int n,k;
int a[100001];
int lb[100001],ub[100001];
char temp[100];
vi buc[100001];
void cl(vi x) {
	int l=-1,r=x.size();
	for (int i=0;i<x.size();i++)
		if (a[x[i]]==inf+1) {
			if (lb[x[i]]<=0&&ub[x[i]]>=0) l=i;
			else if (l!=-1&&r==x.size()) r=i;
		}
	if (l!=-1) {
		if (r==x.size()) r--;
		int mid=l+r>>1;
		a[x[mid]]=0;
		for (int i=mid+1;i<x.size();i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i-1]]+1;
		for (int i=mid-1;~i;i--)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i+1]]-1;
	}
	else {
		for (int i=0;i<x.size();i++)
			if (a[x[i]]==inf+1)
				if (lb[x[i]]>0)
					a[x[i]]=a[x[i-1]]+1;
		for (int i=x.size()-1;~i;i--)
			if (a[x[i]]==inf+1)
				if (ub[x[i]]<0)
					a[x[i]]=a[x[i+1]]-1;
	}
}
bool solve() {
	for (int i=k+1;i<=n;i++)
		if (a[i]==inf+1) {
			if (a[i-k]==inf+1) lb[i]=lb[i-k]+1;
			else lb[i]=a[i-k]+1;
		}
	for (int i=n-k;i;i--)
		if (a[i]==inf+1) {
			if (a[i+k]==inf+1) ub[i]=ub[i+k]-1;
			else ub[i]=a[i+k]-1;
		}
	for (int i=1;i<=n;i++)
		if (a[i]==inf+1) {
			if (lb[i]>ub[i]) return 0;
		}
		else {
			if (i>k)
				if (a[i-k]==inf+1) {
					if (lb[i-k]>=a[i]) return 0;
				}
				else if (a[i]<=a[i-k]) return 0;
			if (i+k<=n)
				if (a[i+k]==inf+1) {
					if (ub[i+k]<=a[i]) return 0;
				}
				//else if (a[i]>=a[i+k]) return 0;
		}
	for (int i=1;i<=n;i++)
		buc[(i-1)%k+1].pb(i);
	for (int i=1;i<=k;i++) cl(buc[i]);
	return 1;
}
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) {
		scanf("%s",temp);
		if (temp[0]=='?') lb[i]=-inf,ub[i]=inf,a[i]=inf+1;
		else a[i]=atoi(temp);
	}
	if (!solve()) puts("Incorrect sequence");
	else for (int i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' ');
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define vi vector<int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define bg(a,n) for(int i=1;i<=(n);printf("%d%s",a[i],i==n?"\n":" "),i++)
using namespace std;
typedef long long LL;
const int inf=1e9;

int n,k;
int a[100001];
int lb[100001],ub[100001];
char temp[100];
vi buc[100001];
void cl(vi x) {
	int l=-1,r=x.size();
	for (int i=0;i<x.size();i++)
		if (a[x[i]]==inf+1) {
			if (lb[x[i]]<=0&&ub[x[i]]>=0) { if (l==-1) l=i; }
			else if (l!=-1&&r==x.size()) r=i;
		}
	if (l!=-1) {
		if (r==x.size()) r--;
		int mid=l+r>>1;
		a[x[mid]]=0;
		for (int i=mid+1;i<x.size();i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i-1]]+1;
		for (int i=mid-1;~i;i--)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i+1]]-1;
	}
	else {
		for (int i=0;i<x.size();i++)
			if (a[x[i]]==inf+1)
				if (lb[x[i]]>0)
					a[x[i]]=a[x[i-1]]+1;
		for (int i=x.size()-1;~i;i--)
			if (a[x[i]]==inf+1)
				if (ub[x[i]]<0)
					a[x[i]]=a[x[i+1]]-1;
	}
}
bool solve() {
	for (int i=k+1;i<=n;i++)
		if (a[i]==inf+1) {
			if (a[i-k]==inf+1) lb[i]=lb[i-k]+1;
			else lb[i]=a[i-k]+1;
		}
	for (int i=n-k;i;i--)
		if (a[i]==inf+1) {
			if (a[i+k]==inf+1) ub[i]=ub[i+k]-1;
			else ub[i]=a[i+k]-1;
		}
	for (int i=1;i<=n;i++)
		if (a[i]==inf+1) {
			if (lb[i]>ub[i]) return 0;
		}
		else {
			if (i>k)
				if (a[i-k]==inf+1) {
					if (lb[i-k]>=a[i]) return 0;
				}
				else if (a[i]<=a[i-k]) return 0;
			if (i+k<=n)
				if (a[i+k]==inf+1) {
					if (ub[i+k]<=a[i]) return 0;
				}
				//else if (a[i]>=a[i+k]) return 0;
		}
	for (int i=1;i<=n;i++)
		buc[(i-1)%k+1].pb(i);
	for (int i=1;i<=k;i++) cl(buc[i]);
	return 1;
}
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) {
		scanf("%s",temp);
		if (temp[0]=='?') lb[i]=-inf,ub[i]=inf,a[i]=inf+1;
		else a[i]=atoi(temp);
	}
	if (!solve()) puts("Incorrect sequence");
	else for (int i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' ');
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define vi vector<int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define bg(a,n) for(int i=1;i<=(n);printf("%d%s",a[i],i==n?"\n":" "),i++)
using namespace std;
typedef long long LL;
const int inf=1e9;

int n,k;
int a[100001];
int lb[100001],ub[100001];
char temp[100];
vi buc[100001];
void cl(vi x) {
	int l=-1,r=x.size();
	for (int i=0;i<x.size();i++)
		if (a[x[i]]==inf+1) {
			if (lb[x[i]]<=0&&ub[x[i]]>=0) l=i;
			else if (l!=-1&&r==x.size()) r=i;
		}
	if (l!=-1) {
		if (r==x.size()) r--;
		int mid=l+r>>1;
		a[x[mid]]=0;
		for (int i=mid+1;i<x.size();i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i-1]]+1;
		for (int i=mid-1;~i;i++)
			if (a[x[i]]==inf+1)
				a[x[i]]=a[x[i+1]]-1;
	}
	else {
		for (int i=0;i<x.size();i++)
			if (a[x[i]]==inf+1)
				if (lb[x[i]]>0)
					a[x[i]]=a[x[i-1]]+1;
		for (int i=x.size()-1;~i;i--)
			if (a[x[i]]==inf+1)
				if (ub[x[i]]<0)
					a[x[i]]=a[x[i+1]]-1;
	}
}
bool solve() {
	for (int i=k+1;i<=n;i++)
		if (a[i]==inf+1) {
			if (a[i-k]==inf+1) lb[i]=lb[i-k]+1;
			else lb[i]=a[i-k]+1;
		}
	for (int i=n-k;i;i--)
		if (a[i]==inf+1) {
			if (a[i+k]==inf+1) ub[i]=ub[i+k]-1;
			else ub[i]=a[i+k]-1;
		}
	for (int i=1;i<=n;i++)
		if (a[i]==inf+1) {
			if (lb[i]>ub[i]) return 0;
		}
		else if (i>k)
			if (a[i-k]==inf+1) {
				if (lb[i-k]>=a[i]) return 0;
			}
			else if (a[i]<=a[i-k]) return 0;
	for (int i=1;i<=n;i++)
		buc[(i-1)%k+1].pb(i);
	for (int i=1;i<=k;i++) cl(buc[i]);
	return 1;
}
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) {
		scanf("%s",temp);
		if (temp[0]=='?') lb[i]=-inf,ub[i]=inf,a[i]=inf+1;
		else a[i]=atoi(temp);
	}
	if (!solve()) puts("Incorrect sequence");
	else for (int i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' ');
	return 0;
}


# include <iostream>
# include<algorithm>
#include <stdio.h>
# include <cstdlib>
using namespace std;
long a[1000000];
bool no[1000000];
char curnum[1000];
int j=-1;
int main()
{
    int n,k;
    cin>>n>>k;
    for (int i=0;i<n;i++)
    {
        cin>>curnum;
        if (curnum[0]=='?')
            no[i]=1;
        else
            a[i]=atoi(curnum);
        if (i>=k)
            j=a[i-k];
        if (no[i])
            a[i]=j+1;
    }
    long long sum=0;
    for (int i=0;i<k;i++)
        sum+=a[i];
    for (int i=k;i<n;i++)
    {
        long long last=sum;
        sum+=a[i];
        sum-=a[i-k];
        if (sum<=last)
        {
            cout<<"Incorrect sequence"<<endl;
            return 0;
        }
    }
    for (int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


# include <iostream>
# include<algorithm>
#include <stdio.h>
# include <cstdlib>
using namespace std;
long a[1000000];
bool no[1000000];
char curnum[1000];
int j;
int main()
{
    int n,k;
    cin>>n>>k;
    for (int i=0;i<n;i++)
    {
        cin>>curnum;
        if (curnum[0]=='?')
            no[i]=1,j--;
        else
            a[i]=atoi(curnum);
    }
    j/=2;
    for (int i=0;i<n;i++)
    {
        if (i>=k)
            j=a[i-k];
        if (no[i])
            a[i]=j+1;
    }
    long long sum=0;
    for (int i=0;i<k;i++)
        sum+=a[i];
    for (int i=k;i<n;i++)
    {
        long long last=sum;
        sum+=a[i];
        sum-=a[i-k];
        if (sum<=last)
        {
            cout<<"Incorrect sequence"<<endl;
            return 0;
        }
    }
    for (int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


# include <iostream>
# include<algorithm>
#include <stdio.h>
# include <cstdlib>
using namespace std;
long a[1000000];
bool no[1000000];
char curnum[1000];
bool vis[1000000];
    long long n,k;
long long calc(long long st,long long en,long long num)
{
    if (en<=1)
        return en-num;
    if (st>=-1)
        return st+1;
    long long x=-num/2;
    if (x<=st)
        x+=(st-x+1);
    if (x+num-1>=en)
        x=en-num;
    return x;
}
void fil(long long st,long long en,long long j)
{
    for (long long i=st;i<=en;i+=k)
        if (no[i])
            a[i]=j,j++;
}
int main()
{
    cin>>n>>k;
    for (long long i=0;i<n;i++)
    {
        cin>>curnum;
        if (curnum[0]=='?')
        {
            no[i]=1;
        }
        else
            a[i]=atoi(curnum);
    }
    for (long long i=0;i<n;i++)
    {
        if (vis[i]) continue;
        long long num=0;
        long long last=3000000000;
        last*=-1;
        long long idx=i;
        for (long long x=i;x<n;x+=k)
        {
            vis[x]=1;
            if (no[x])
                num++;
            if (no[x]==0 || x+k>=n)
            {
                if (num==0)
                {
                    idx=x;
                    last=a[x];
                    continue;
                }
                long long en=a[x];
                if (no[x]==1)
                    en=3000000000;
                if (en-last-1<num)
                {
                    cout<<"Incorrect sequence"<<endl;
                    return 0;
                }
                long long st=calc(last,en,num);
                fil(idx,x,st);
                num=0;
                idx=x;
                last=en;
            }
        }
    }
     long long sum=0;
    for (long long i=0;i<k;i++)
        sum+=a[i];
    for (long long i=k;i<n;i++)
    {
        long long last=sum;
        sum+=a[i];
        sum-=a[i-k];
        if (sum<=last)
        {
            cout<<"Incorrect sequence"<<endl;
            return 0;
        }
    }
    for (long long i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


# include <iostream>
# include<algorithm>
#include <stdio.h>
# include <cstdlib>
using namespace std;
long a[1000000];
bool no[1000000];
char curnum[1000];
bool vis[1000000];
    long long n,k;
long long calc(long long st,long long en,long long num)
{
    if (en<=1)
        return en-num;
    if (st>=-1)
        return st+1;
    long long x=-num/2;
    if (x<=st)
        x+=(st-x+1);
    if (x+num-1>=en)
        x=en-num;
    return x;
}
void fil(long long st,long long en,long long j)
{
    for (long long i=st;i<=en;i+=k)
        if (no[i])
            a[i]=j,j++;
}
int main()
{
    cin>>n>>k;
    for (long long i=0;i<n;i++)
    {
        cin>>curnum;
        if (curnum[0]=='?')
        {
            no[i]=1;
        }
        else
            a[i]=atoi(curnum);
    }
    for (long long i=0;i<n;i++)
    {
        if (vis[i]) continue;
        long long num=0;
        long long last=(long long)-3000000000;
        long long idx=i;
        for (long long x=i;x<n;x+=k)
        {
            vis[x]=1;
            if (no[x])
                num++;
            else if (no[x]==0)
            {
                if (num==0)
                    continue;
                long long en=a[x];
                if (no[x]==1)
                    en=3000000000;
                if (en-last-1<num)
                {
                    cout<<"Incorrect sequence"<<endl;
                    return 0;
                }
                long long st=calc(last,en,num);
                fil(idx,x,st);
                num=0;
                idx=x;
                last=en;
            }
        }
    }
     long long sum=0;
    for (long long i=0;i<k;i++)
        sum+=a[i];
    for (long long i=k;i<n;i++)
    {
        long long last=sum;
        sum+=a[i];
        sum-=a[i-k];
        if (sum<=last)
        {
            cout<<"Incorrect sequence"<<endl;
            return 0;
        }
    }
    for (long long i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


# include <iostream>
# include<algorithm>
#include <stdio.h>
# include <cstdlib>
using namespace std;
long a[1000000];
bool no[1000000];
char curnum[1000];
bool vis[1000000];
    long long n,k;
long long calc(long long st,long long en,long long num)
{
    if (en<=1)
        return en-num;
    if (st>=-1)
        return st+1;
    long long x=-num/2;
    if (x<=st)
        x+=(st-x+1);
    if (x+num-1>=en)
        x=en-num;
    return x;
}
void fil(long long st,long long en,long long j)
{
    for (long long i=st;i<=en;i+=k)
        if (no[i])
            a[i]=j,j++;
}
int main()
{
    cin>>n>>k;
    for (long long i=0;i<n;i++)
    {
        cin>>curnum;
        if (curnum[0]=='?')
        {
            no[i]=1;
        }
        else
            a[i]=atoi(curnum);
    }
    for (long long i=0;i<n;i++)
    {
        if (vis[i]) continue;
        long long num=0;
        long long last=3000000000;
        last*=-1;
        long long idx=i;
        for (long long x=i;x<n;x+=k)
        {
            vis[x]=1;
            if (no[x])
                num++;
            if (no[x]==0 || x+k>=n)
            {
                if (num==0)
                    continue;
                long long en=a[x];
                if (no[x]==1)
                    en=3000000000;
                if (en-last-1<num)
                {
                    cout<<"Incorrect sequence"<<endl;
                    return 0;
                }
                long long st=calc(last,en,num);
                fil(idx,x,st);
                num=0;
                idx=x;
                last=en;
            }
        }
    }
     long long sum=0;
    for (long long i=0;i<k;i++)
        sum+=a[i];
    for (long long i=k;i<n;i++)
    {
        long long last=sum;
        sum+=a[i];
        sum-=a[i-k];
        if (sum<=last)
        {
            cout<<"Incorrect sequence"<<endl;
            return 0;
        }
    }
    for (long long i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


# include <iostream>
# include<algorithm>
#include <stdio.h>
# include <cstdlib>
using namespace std;
long a[1000000];
bool no[1000000];
char curnum[1000];
bool vis[1000000];
int main()
{
    int n,k;
    cin>>n>>k;
    for (int i=0;i<n;i++)
    {
        cin>>curnum;
        if (curnum[0]=='?')
        {
            no[i]=1;
        }
        else
            a[i]=atoi(curnum);
    }
    for (int i=0;i<n;i++)
    {
        if (vis[i]) continue;
        bool num=1;
        int j=0;
        for (int x=i;x<n;x+=k)
        {
            vis[x]=1;
            if (no[x]==0)
                num=0;
            if (no[x])
                j-=num;
        }
        j=j/2;
        for (int x=i;x<n;x+=k)
        {
            if (x>=n)
                break;
            if (no[x])
                a[x]=j;
            if (no[x]==0)
                j=a[x]+1;
            else
                j++;
        }
    }
     long long sum=0;
    for (int i=0;i<k;i++)
        sum+=a[i];
    for (int i=k;i<n;i++)
    {
        long long last=sum;
        sum+=a[i];
        sum-=a[i-k];
        if (sum<=last)
        {
            cout<<"Incorrect sequence"<<endl;
            return 0;
        }
    }
    for (int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


# include <iostream>
# include<algorithm>
#include <stdio.h>
# include <cstdlib>
using namespace std;
long a[1000000];
bool no[1000000];
char curnum[1000];
int j;
int main()
{
    int n,k;
    cin>>n>>k;
    for (int i=0;i<n;i++)
    {
        cin>>curnum;
        if (curnum[0]=='?')
            no[i]=1,j--;
        else
            a[i]=atoi(curnum);
    }
    j/=2;
    for (int i=0;i<n;i++)
    {
        if (i>=k)
            j=a[i-k]+1;
        if (no[i])
            a[i]=j;
    }
    long long sum=0;
    for (int i=0;i<k;i++)
        sum+=a[i];
    for (int i=k;i<n;i++)
    {
        long long last=sum;
        sum+=a[i];
        sum-=a[i-k];
        if (sum<=last)
        {
            cout<<"Incorrect sequence"<<endl;
            return 0;
        }
    }
    for (int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;

int n,k;
const int q=2*1e9+1;
const int maxn=1e5+7;
const int inf=2*1e9+7;
struct edge{
   int u,v,d;
};
vector<edge>edges;
vector<int >g[maxn];
void add_edge(int u,int v,int d){
    g[u].push_back(edges.size());
edges.push_back((edge){u,v,d} );
}
int dis[maxn];
int a[maxn];
bool inq[maxn];
int cnt[maxn];
int get()
{
    char c=' ';
    while(!(c=='?'||(c>='0'&&c<='9')||c=='-'))
    {
        c=getchar();
    }
    if(c=='?')return q;
    int sb=1;
    int tot=0;
    if(c=='-')sb=-1,c=getchar();
    do
    {
        tot=tot*10+c-'0';
        c=getchar();
    }while(c>='0'&&c<='9');
    return tot*sb;
}
bool solve()
{
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i-k<0&&i+k>=n)a[i]=0;
            if(i-k<0&&i+k<n)
            {
                if(a[i+k]!=q)
                {
                    if(a[i+k]<=0)a[i]=a[i+k]-1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k>=n)
            {
                if(a[i-k]!=q)
                {
                    if(a[i-k]>=0)a[i]=a[i-k]+1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k<n)
            {
              //  printf("%d %d\n",a[i-k],a[i+k]);
                if(a[i-k]==q||a[i+k]==q)continue;
                if(a[i-k]>=a[i+k])return 0;
                if(a[i-k]>=0)a[i]=a[i-k]+1;
                else if(a[i+k]<=0)a[i]=a[i+k]-1;
                else a[i-k]=0;
            }
        }
    }

int start;
    int minn=0,maxx=inf;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=q&&i+k<n&&a[i+k]==q)
        {
            vector<int>cmp;
            minn=a[i];
            maxx=inf;
            int sb=i+k;
            while(sb+k<n)
            {
                cmp.push_back(sb);
                sb+=k;
                if(a[sb]!=q)
                {
                    maxx=a[sb];
                    break;
                }
            }
            if(maxx==inf)
            {
                start=max(a[i]+1,-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
            else
            {
                if(maxx-minn-1<=cmp.size())return 0;
                start=min(maxx-(int)cmp.size(),max(a[i]+1,-(int)cmp.size()/2));
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]!=q&&i-k>=0&&a[i-k]==q)
        {
            vector<int>cmp;
            maxx=a[i];
            int sb=i-k;
            while(sb-k<n)
            {
                cmp.push_back(sb);
                sb-=k;
            }
            if(maxx==inf)
            {
                start=min(maxx-(int)cmp.size(),-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
     for(int i=0;i<n;i++)
    {
        vector<int>cmp;
        if(a[i]==q)
        {
            int sb=i;
            while(sb<n)
            {
               cmp.push_back(sb);
               sb+=k;
            }
            start=-(int)cmp.size()/2;
            for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
        }
    }
    return 1;
}
int main()
{
    scanf("%d %d",&n,&k);getchar();
    for(int i=0;i<n;i++)a[i]=get();
    if(!solve())printf("Incorrect sequence\n");
    else
    {
        for(int i=0;i<n;i++)printf("%d ",a[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;

int n,k;
const int q=1e9+1;
const int maxn=1e5+7;
const int inf=2*1e9+7;
struct edge{
   int u,v,d;
};
vector<edge>edges;
vector<int >g[maxn];
void add_edge(int u,int v,int d){
    g[u].push_back(edges.size());
edges.push_back((edge){u,v,d} );
}
int dis[maxn];
int a[maxn];
bool inq[maxn];
int cnt[maxn];
int get()
{
    char c=' ';
    while(!(c=='?'||(c>='0'&&c<='9')||c=='-'))
    {
        c=getchar();
    }
    if(c=='?')return q;
    int sb=1;
    int tot=0;
    if(c=='-')sb=-1,c=getchar();
    do
    {
        tot=tot*10+c-'0';
        c=getchar();
    }while(c>='0'&&c<='9');
    return tot*sb;
}
bool solve()
{
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i-k<0&&i+k>=n)a[i]=0;
            if(i-k<0&&i+k<n)
            {
                if(a[i+k]!=q)
                {
                    if(a[i+k]<=0)a[i]=a[i+k]-1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k>=n)
            {
                if(a[i-k]!=q)
                {
                    if(a[i-k]>=0)a[i]=a[i-k]+1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k<n)
            {
              //  printf("%d %d\n",a[i-k],a[i+k]);
                if(a[i-k]==q||a[i+k]==q)continue;
                if(a[i-k]>=a[i+k])return 0;
                if(a[i-k]>=0)a[i]=a[i-k]+1;
                else if(a[i+k]<=0)a[i]=a[i+k]-1;
                else a[i-k]=0;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i+k<n&&a[i+k]==q)
            {
                add_edge(i+k,i,-1);
            }
            if(i-k>=0&&a[i-k]!=q)
            {
                add_edge(i,n,-a[i-k]-1);
            }
            if(i+k<n&&a[i+k]!=q)
            {
                add_edge(n,i,a[i+k]-1);
            }
        }
    }
     queue<int >que;
    for(int i=0;i<=n;i++){dis[i]=0;que.push(i);}

    while(!que.empty()){
        int u=que.front();que.pop();
        inq[u]=0;
        for(int i=0;i<g[u].size();i++){
            edge &e=edges[g[u][i]];
            int v=e.v;
            int d=e.d;
            if(dis[v]>dis[u]+d){
                dis[v]=dis[u]+d;
                if(!inq[v]){
                    que.push(v);
                    inq[v]=1;
                    if(++cnt[v]>n+1)return 0;
                }
            }
        }
    }
    for(int i=0;i<n;i++)if(a[i]==q)a[i]=dis[i];
    for(int i=0;i<n;i++)
    {
        if(i+k<n&&a[i]>=a[i+k])return 0;
    }
    return 1;
}
int main()
{
    scanf("%d %d",&n,&k);getchar();
    for(int i=0;i<n;i++)a[i]=get();
    if(!solve())printf("Incorrect sequence\n");
    else
    {
        for(int i=0;i<n;i++)printf("%d ",a[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;

int n,k;
const int q=2*1e9+1;
const int maxn=1e5+7;
const int inf=2*1e9+7;
struct edge{
   int u,v,d;
};
vector<edge>edges;
vector<int >g[maxn];
void add_edge(int u,int v,int d){
    g[u].push_back(edges.size());
edges.push_back((edge){u,v,d} );
}
int dis[maxn];
int a[maxn];
bool inq[maxn];
int cnt[maxn];
int get()
{
    char c=' ';
    while(!(c=='?'||(c>='0'&&c<='9')||c=='-'))
    {
        c=getchar();
    }
    if(c=='?')return q;
    int sb=1;
    int tot=0;
    if(c=='-')sb=-1,c=getchar();
    do
    {
        tot=tot*10+c-'0';
        c=getchar();
    }while(c>='0'&&c<='9');
    return tot*sb;
}
bool solve()
{
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i-k<0&&i+k>=n)a[i]=0;
            if(i-k<0&&i+k<n)
            {
                if(a[i+k]!=q)
                {
                    if(a[i+k]<=0)a[i]=a[i+k]-1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k>=n)
            {
                if(a[i-k]!=q)
                {
                    if(a[i-k]>=0)a[i]=a[i-k]+1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k<n)
            {
              //  printf("%d %d\n",a[i-k],a[i+k]);
                if(a[i-k]==q||a[i+k]==q)continue;
                if(a[i-k]>=a[i+k])return 0;
                if(a[i-k]>=0)a[i]=a[i-k]+1;
                else if(a[i+k]<=0)a[i]=a[i+k]-1;
                else a[i-k]=0;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i+k<n&&a[i+k]==q)
            {
                add_edge(i+k,i,-1);
            }
            if(i-k>=0&&a[i-k]!=q)
            {
                add_edge(i,n,-a[i-k]-1);
            }
            if(i+k<n&&a[i+k]!=q)
            {
                add_edge(n,i,a[i+k]-1);
            }
        }
    }
     queue<int >que;
    for(int i=0;i<=n;i++){dis[i]=0;que.push(i);}

    while(!que.empty()){
        int u=que.front();que.pop();
        inq[u]=0;
        for(int i=0;i<g[u].size();i++){
            edge &e=edges[g[u][i]];
            int v=e.v;
            int d=e.d;
            if(dis[v]>dis[u]+d){
                dis[v]=dis[u]+d;
                if(!inq[v]){
                    que.push(v);
                    inq[v]=1;
                    if(++cnt[v]>n+1)return 0;
                }
            }
        }
    }
    for(int i=0;i<n;i++)if(a[i]==q)a[i]=dis[i];
    for(int i=0;i<n;i++)
    {
        if(i+k<n&&a[i]>=a[i+k])return 0;
    }
    return 1;
}
int main()
{
    scanf("%d %d",&n,&k);getchar();
    for(int i=0;i<n;i++)a[i]=get();
    if(!solve())printf("Incorrect sequence\n");
    else
    {
        for(int i=0;i<n;i++)printf("%d ",a[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;

int n,k;
const int q=2*1e9+1;
const int maxn=1e5+7;
const int inf=2*1e9+7;
struct edge{
   int u,v,d;
};
vector<edge>edges;
vector<int >g[maxn];
void add_edge(int u,int v,int d){
    g[u].push_back(edges.size());
edges.push_back((edge){u,v,d} );
}
int dis[maxn];
int a[maxn];
bool inq[maxn];
int cnt[maxn];
int get()
{
    char c=' ';
    while(!(c=='?'||(c>='0'&&c<='9')||c=='-'))
    {
        c=getchar();
    }
    if(c=='?')return q;
    int sb=1;
    int tot=0;
    if(c=='-')sb=-1,c=getchar();
    do
    {
        tot=tot*10+c-'0';
        c=getchar();
    }while(c>='0'&&c<='9');
    return tot*sb;
}
bool solve()
{
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i-k<0&&i+k>=n)a[i]=0;
            if(i-k<0&&i+k<n)
            {
                if(a[i+k]!=q)
                {
                    if(a[i+k]<=0)a[i]=a[i+k]-1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k>=n)
            {
                if(a[i-k]!=q)
                {
                    if(a[i-k]>=0)a[i]=a[i-k]+1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k<n)
            {
              //  printf("%d %d\n",a[i-k],a[i+k]);
                if(a[i-k]==q||a[i+k]==q)continue;
                if(a[i-k]>=a[i+k])return 0;
                if(a[i-k]>=0)a[i]=a[i-k]+1;
                else if(a[i+k]<=0)a[i]=a[i+k]-1;
                else a[i-k]=0;
            }
        }
    }

int start;
    int minn=0,maxx=inf;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=q&&i+k<n&&a[i+k]==q)
        {
            vector<int>cmp;
            minn=a[i];
            maxx=inf;
            int sb=i+k;
            while(sb+k<n)
            {
                cmp.push_back(sb);
                sb+=k;
                if(a[sb]!=q)
                {
                    maxx=a[sb];
                    break;
                }
            }
            if(maxx==inf)
            {
                start=max(a[i]+1,-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
            else
            {
                if(maxx-minn-1<=cmp.size())return 0;
                start=min(maxx-(int)cmp.size(),max(a[i]+1,-(int)cmp.size()/2));
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]!=q&&i-k>=0&&a[i-k]==q)
        {
            vector<int>cmp;
            maxx=a[i];
            int sb=i-k;
            while(sb-k<n)
            {
                cmp.push_back(sb);
                sb-=k;
            }
            if(maxx==inf)
            {
                start=min(maxx-(int)cmp.size(),-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
     for(int i=0;i<n;i++)
    {
        vector<int>cmp;
        if(a[i]==q)
        {
            int sb=i;
            while(sb<n)
            {
               cmp.push_back(sb);
               sb+=k;
            }
            start=-(int)cmp.size()/2;
            for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
        }
    }
     for(int i=0;i<n;i++)
    {
        if(i+k<n&&a[i]>=a[i+k])return 0;
    }
    return 1;
}
int main()
{
    scanf("%d %d",&n,&k);getchar();
    for(int i=0;i<n;i++)a[i]=get();
    if(!solve())printf("Incorrect sequence\n");
    else
    {
        for(int i=0;i<n;i++)printf("%d ",a[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;

int n,k;
const int q=2*1e9+1;
const int maxn=1e5+7;
const int inf=2*1e9+7;
struct edge{
   int u,v,d;
};
vector<edge>edges;
vector<int >g[maxn];
void add_edge(int u,int v,int d){
    g[u].push_back(edges.size());
edges.push_back((edge){u,v,d} );
}
int dis[maxn];
int a[maxn];
bool inq[maxn];
int cnt[maxn];
int get()
{
    char c=' ';
    while(!(c=='?'||(c>='0'&&c<='9')||c=='-'))
    {
        c=getchar();
    }
    if(c=='?')return q;
    int sb=1;
    int tot=0;
    if(c=='-')sb=-1,c=getchar();
    do
    {
        tot=tot*10+c-'0';
        c=getchar();
    }while(c>='0'&&c<='9');
    return tot*sb;
}
bool solve()
{
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i-k<0&&i+k>=n)a[i]=0;
            if(i-k<0&&i+k<n)
            {
                if(a[i+k]!=q)
                {
                    if(a[i+k]<=0)a[i]=a[i+k]-1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k>=n)
            {
                if(a[i-k]!=q)
                {
                    if(a[i-k]>=0)a[i]=a[i-k]+1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k<n)
            {
              //  printf("%d %d\n",a[i-k],a[i+k]);
                if(a[i-k]==q||a[i+k]==q)continue;
                if(a[i-k]>=a[i+k])return 0;
                if(a[i-k]>=0)a[i]=a[i-k]+1;
                else if(a[i+k]<=0)a[i]=a[i+k]-1;
                else a[i-k]=0;
            }
        }
    }

int start;
    int minn=0,maxx=inf;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=q&&i+k<n&&a[i+k]==q)
        {
            vector<int>cmp;
            minn=a[i];
            maxx=inf;
            int sb=i+k;
            while(sb<n)
            {
                if(a[sb]!=q)
                {
                    maxx=a[sb];
                    break;
                }
                cmp.push_back(sb);
                sb+=k;

            }
            if(maxx==inf)
            {
                start=max(a[i]+1,-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
            else
            {
                if(maxx-minn-1<=cmp.size())return 0;
                start=min(maxx-(int)cmp.size(),max(a[i]+1,-(int)cmp.size()/2));
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]!=q&&i-k>=0&&a[i-k]==q)
        {
            vector<int>cmp;
            maxx=a[i];
            int sb=i-k;
            while(sb<n)
            {
                cmp.push_back(sb);
                sb-=k;
            }
            if(maxx==inf)
            {
                start=min(maxx-(int)cmp.size(),-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
     for(int i=0;i<n;i++)
    {
        vector<int>cmp;
        if(a[i]==q)
        {
            int sb=i;
            while(sb<n)
            {
               cmp.push_back(sb);
               sb+=k;
            }
            start=-(int)cmp.size()/2;
            for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
        }
    }
     for(int i=0;i<n;i++)
    {
        if(i+k<n&&a[i]>=a[i+k])return 0;
    }

    return 1;
}
int main()
{
    scanf("%d %d",&n,&k);getchar();
    for(int i=0;i<n;i++)a[i]=get();
    if(!solve())printf("Incorrect sequence\n");
    else
    {
        for(int i=0;i<n;i++)printf("%d ",a[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;

int n,k;
const int q=2*1e9+1;
const int maxn=1e5+7;
const int inf=2*1e9+7;
struct edge{
   int u,v,d;
};
vector<edge>edges;
vector<int >g[maxn];
void add_edge(int u,int v,int d){
    g[u].push_back(edges.size());
edges.push_back((edge){u,v,d} );
}
int dis[maxn];
int a[maxn];
bool inq[maxn];
int cnt[maxn];
int get()
{
    char c=' ';
    while(!(c=='?'||(c>='0'&&c<='9')||c=='-'))
    {
        c=getchar();
    }
    if(c=='?')return q;
    int sb=1;
    int tot=0;
    if(c=='-')sb=-1,c=getchar();
    do
    {
        tot=tot*10+c-'0';
        c=getchar();
    }while(c>='0'&&c<='9');
    return tot*sb;
}
bool solve()
{

int start;
    int minn=0,maxx=inf;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=q&&i+k<n&&a[i+k]==q)
        {
            vector<int>cmp;
            minn=a[i];
            maxx=inf;
            int sb=i+k;
            while(sb<n)
            {
                if(a[sb]!=q)
                {
                    maxx=a[sb];
                    break;
                }
                cmp.push_back(sb);
                sb+=k;
            }
            if(maxx==inf)
            {
                start=max(a[i]+1,-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
            else
            {
                if(maxx-minn-1<cmp.size())return 0;
                start=min(maxx-(int)cmp.size(),max(a[i]+1,-(int)cmp.size()/2));
              //  printf("%d\n",start);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]!=q&&i-k>=0&&a[i-k]==q)
        {
            vector<int>cmp;
            maxx=a[i];
            int sb=i-k;
            while(sb>=0)
            {
                cmp.push_back(sb);
                sb-=k;
            }
            start=min(maxx-(int)cmp.size(),-(int)cmp.size()/2);
            for(int j=cmp.size()-1;j>=0;j--)a[cmp[j]]=start++;

        }
    }
     for(int i=0;i<n;i++)
    {
        vector<int>cmp;
        if(a[i]==q)
        {
            int sb=i;
            while(sb<n)
            {
               cmp.push_back(sb);
               sb+=k;
            }
            start=-(int)cmp.size()/2;
            for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
        }
    }
     for(int i=0;i<n;i++)
    {
        if(i+k<n&&a[i]>=a[i+k])return 0;
    }

    return 1;
}
int main()
{
    scanf("%d %d",&n,&k);getchar();
    for(int i=0;i<n;i++)a[i]=get();
    if(!solve())printf("Incorrect sequence\n");
    else
    {
        for(int i=0;i<n;i++)printf("%d ",a[i]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;

int n,k;
const int q=2*1e9+1;
const int maxn=1e5+7;
const int inf=2*1e9+7;
struct edge{
   int u,v,d;
};
vector<edge>edges;
vector<int >g[maxn];
void add_edge(int u,int v,int d){
    g[u].push_back(edges.size());
edges.push_back((edge){u,v,d} );
}
int dis[maxn];
int a[maxn];
bool inq[maxn];
int cnt[maxn];
int get()
{
    char c=' ';
    while(!(c=='?'||(c>='0'&&c<='9')||c=='-'))
    {
        c=getchar();
    }
    if(c=='?')return q;
    int sb=1;
    int tot=0;
    if(c=='-')sb=-1,c=getchar();
    do
    {
        tot=tot*10+c-'0';
        c=getchar();
    }while(c>='0'&&c<='9');
    return tot*sb;
}
bool solve()
{
    for(int i=0;i<n;i++)
    {
        if(a[i]==q)
        {
            if(i-k<0&&i+k>=n)a[i]=0;
            if(i-k<0&&i+k<n)
            {
                if(a[i+k]!=q)
                {
                    if(a[i+k]<=0)a[i]=a[i+k]-1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k>=n)
            {
                if(a[i-k]!=q)
                {
                    if(a[i-k]>=0)a[i]=a[i-k]+1;
                    else a[i]=0;
                }
            }
            if(i-k>=0&&i+k<n)
            {
              //  printf("%d %d\n",a[i-k],a[i+k]);
                if(a[i-k]==q||a[i+k]==q)continue;
                if(a[i-k]>=a[i+k])return 0;
                if(a[i-k]>=0)a[i]=a[i-k]+1;
                else if(a[i+k]<=0)a[i]=a[i+k]-1;
                else a[i-k]=0;
            }
        }
    }

int start;
    int minn=0,maxx=inf;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=q&&i+k<n&&a[i+k]==q)
        {
            vector<int>cmp;
            minn=a[i];
            maxx=inf;
            int sb=i+k;
            while(sb<n)
            {
                if(a[sb]!=q)
                {
                    maxx=a[sb];
                    break;
                }
                cmp.push_back(sb);
                sb+=k;

            }
            if(maxx==inf)
            {
                start=max(a[i]+1,-(int)cmp.size()/2);
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
            else
            {
                if(maxx-minn-1<=cmp.size())return 0;
                start=min(maxx-(int)cmp.size(),max(a[i]+1,-(int)cmp.size()/2));
                for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
            }
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]!=q&&i-k>=0&&a[i-k]==q)
        {
            vector<int>cmp;
            maxx=a[i];
            int sb=i-k;
            while(sb>=0)
            {
                cmp.push_back(sb);
                sb-=k;
            }
            start=min(maxx-(int)cmp.size(),-(int)cmp.size()/2);
            for(int j=cmp.size()-1;j>=0;j--)a[cmp[j]]=start++;

        }
    }
     for(int i=0;i<n;i++)
    {
        vector<int>cmp;
        if(a[i]==q)
        {
            int sb=i;
            while(sb<n)
            {
               cmp.push_back(sb);
               sb+=k;
            }
            start=-(int)cmp.size()/2;
            for(int j=0;j<cmp.size();j++)a[cmp[j]]=start++;
        }
    }
     for(int i=0;i<n;i++)
    {
        if(i+k<n&&a[i]>=a[i+k])return 0;
    }

    return 1;
}
int main()
{
    scanf("%d %d",&n,&k);getchar();
    for(int i=0;i<n;i++)a[i]=get();
    if(!solve())printf("Incorrect sequence\n");
    else
    {
        for(int i=0;i<n;i++)printf("%d ",a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, kk;
    cin >> n >> kk;

    mset(mark, 0);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % kk].pb(i);
    }

    // rep(i, kk) {
    //  dbg(i);
    //  for (int x : dep[i]) dbs(x); dbn;
    // }

    rep(i, kk) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(mark[dep[i][j]]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]] > 0) ++k;

            assert(j < k);

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[dep[i][k]] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[dep[i][k]] - 1);
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                    }
                } else {
                    if((ll)a[dep[i][k]] - (ll)lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[dep[i][k]] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else if(a[dep[i][k]] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[dep[i][k]]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[dep[i][k]] - 1);
                            for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, kk;
    cin >> n >> kk;

    mset(mark, false);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % kk].pb(i);
    }

    rep(i, kk) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(!mark[j]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]]) ++k;

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[l] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[l] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[l] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[k] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[l] = a[k] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[k] - 1);
                        for (int l = k - 1; l >= j; --l) a[l] = maxv - (k - l - 1);
                    }
                } else {
                    if(a[k] - lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[k] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[l] = a[k] - (k - l);
                    } else if(a[k] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[l] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[k]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[k] - 1);
                            for (int l = k - 1; l >= j; --l) a[l] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[l] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, kk;
    cin >> n >> kk;

    mset(mark, 0);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % kk].pb(i);
    }

    // rep(i, kk) {
    //  dbg(i);
    //  for (int x : dep[i]) dbs(x); dbn;
    // }

    rep(i, kk) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(!mark[j]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]] > 0) ++k;

            assert(j < k);

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[dep[i][k]] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[dep[i][k]] - 1);
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                    }
                } else {
                    if((ll)a[dep[i][k]] - (ll)lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[dep[i][k]] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else if(a[dep[i][k]] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[dep[i][k]]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[dep[i][k]] - 1);
                            for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    mset(mark, false);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % k].pb(i);
    }

    rep(i, k) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(!mark[j]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]]) ++k;

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[l] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[l] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[l] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[k] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[l] = a[k] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[k] - 1);
                        for (int l = k - 1; l >= j; --l) a[l] = maxv - (k - l - 1);
                    }
                } else {
                    if(a[k] - lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[k] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[l] = a[k] - (k - l);
                    } else if(a[k] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[l] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[k]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[k] - 1);
                            for (int l = k - 1; l >= j; --l) a[l] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[l] = minv + (l - j);
                        }
                    }
                }
            }
            j = k;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, kk;
    cin >> n >> kk;

    mset(mark, false);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % kk].pb(i);
    }

    // rep(i, kk) {
    //  dbg(i);
    //  for (int x : dep[i]) dbs(x); dbn;
    // }

    rep(i, kk) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(!mark[j]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]]) ++k;

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[k] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[k] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[k] - 1);
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                    }
                } else {
                    if(a[k] - lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[k] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[k] - (k - l);
                    } else if(a[k] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[k]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[k] - 1);
                            for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    mset(mark, false);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % k].pb(i);
    }

    rep(i, k) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(!mark[j]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]]) ++k;

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[l] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[l] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[l] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[k] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[l] = a[k] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[k] - 1);
                        for (int l = k - 1; l >= j; --l) a[l] = maxv - (k - l - 1);
                    }
                } else {
                    if(a[k] - lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[k] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[l] = a[k] - (k - l);
                    } else if(a[k] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[l] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[k]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[k] - 1);
                            for (int l = k - 1; l >= j; --l) a[l] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[l] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, kk;
    cin >> n >> kk;

    mset(mark, 0);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % kk].pb(i);
    }

    // rep(i, kk) {
    //  dbg(i);
    //  for (int x : dep[i]) dbs(x); dbn;
    // }

    rep(i, kk) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(!mark[dep[i][j]]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]] > 0) ++k;

            assert(j < k);

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[dep[i][k]] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[dep[i][k]] - 1);
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                    }
                } else {
                    if((ll)a[dep[i][k]] - (ll)lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[dep[i][k]] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else if(a[dep[i][k]] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[dep[i][k]]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[dep[i][k]] - 1);
                            for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, kk;
    cin >> n >> kk;

    mset(mark, false);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % kk].pb(i);
    }

    // rep(i, kk) {
    //  dbg(i);
    //  for (int x : dep[i]) dbs(x); dbn;
    // }

    rep(i, kk) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(!mark[j]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]]) ++k;

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[dep[i][k]] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[dep[i][k]] - 1);
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                    }
                } else {
                    if((ll)a[dep[i][k]] - (ll)lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[dep[i][k]] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else if(a[dep[i][k]] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[dep[i][k]]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[dep[i][k]] - 1);
                            for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef vector <int> vi;

#define rep(i, n) for(int i = 0; i < (n); ++i)

#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define mset(a, v) memset(a, v, sizeof(a))

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << x << " "
#define dbs(x) cerr << x << " "

const int N = 100100;
const int INF = -(int)2e9;

int a[N], mark[N];
char buf[20];
vi dep[N];

int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, kk;
    cin >> n >> kk;

    mset(mark, 0);
    mset(a, 0);

    rep(i, n) {
        cin >> buf;
        if(buf[0] == '?') mark[i] = true;
        else sscanf(buf, "%d", a + i);
    }

    rep(i, n) {
        dep[i % kk].pb(i);
    }

    // rep(i, kk) {
    //  dbg(i);
    //  for (int x : dep[i]) dbs(x); dbn;
    // }

    rep(i, kk) if(sz(dep[i]) > 1) {
        int lastFixed = INF;
        for(int j = 0; j < sz(dep[i]); ++j) {
            if(mark[dep[i][j]) {
                if(a[dep[i][j]] <= lastFixed) {
                    cout << "Incorrect sequence\n";
                    return 0;
                }
                lastFixed = a[dep[i][j]];
                continue;
            }

            int k = j;
            while (k < sz(dep[i]) and mark[dep[i][k]] > 0) ++k;

            assert(j < k);

            int len = (k - j);
            if(k == sz(dep[i])) {
                if(lastFixed == INF) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = -(len / 2) + (l - j);
                } else if(lastFixed >= 0) {
                    for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                } else {
                    int minv = max(-(len / 2), lastFixed + 1);
                    for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                }
            } else {
                if(lastFixed == INF) {
                    if(a[dep[i][k]] <= 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else {
                        int maxv = min((len / 2), a[dep[i][k]] - 1);
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                    }
                } else {
                    if((ll)a[dep[i][k]] - (ll)lastFixed <= len) {
                        cout << "Incorrect sequence\n";
                        return 0;
                    }
                    if(a[dep[i][k]] < 0 and lastFixed < 0) {
                        for (int l = k - 1; l >= j; --l) a[dep[i][l]] = a[dep[i][k]] - (k - l);
                    } else if(a[dep[i][k]] >= 0 and lastFixed >= 0) {
                        for (int l = j; l < k; ++l) a[dep[i][l]] = lastFixed + l - j + 1;
                    } else {
                        if(abs(a[dep[i][k]]) <= abs(lastFixed)) {
                            int maxv = min((len / 2), a[dep[i][k]] - 1);
                            for (int l = k - 1; l >= j; --l) a[dep[i][l]] = maxv - (k - l - 1);
                        } else {
                            int minv = max(-(len / 2), lastFixed + 1);
                            for (int l = j; l < k; ++l) a[dep[i][l]] = minv + (l - j);
                        }
                    }
                }
            }
            j = k - 1;
        }
    }

    rep(i, n) cout << a[i] << ' ';
    cout << '\n';
    return 0;
}