/*
I could not breath against the wall
The clash of light against the floor
They held me up against the wall
Too young to be ignored

Standing by a building
Leaks out information
Passive death of freedom gets me
Where's my security
Behind my back it goes
Early morning's coming
The risk that I am taking
Recall a song that I heard as a child
No more false immunity
Inside the blistering cold

My youth unknown to me
I'm walking by a wire
What's left from me to breathe
Cold smell of fire
One day I will be free
I was born to be no one
My youth unknown to me
I walked behind the sun

Emptiness within me
Exit signs within me
The one you're looking for is not here
Had no security
He will not come back
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
//#include <memory.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define  INF 100000000
#define eps 1e-13
//#define M_PI 3.141592653589793
//#define mx 1000000000000ll
#define bs 1000000007

//#define free asdfasdfsdadsg
//#define szz 400
//#define pb push_back
#define MAXN 10000
#define free afdshjioey
//#define SIZE 60
#define bsize 2000

using namespace std;

long n;
vector<pair<long, long> > v;
long ar[300000];
long reach[300000][10];
long rspan,need1,need2;
long p,q;
long par[300000][10];
long ps,cur;
long tp,np,niters,m2,m1,qq;

int main(){
//freopen("ascii.in","r",stdin);
//freopen("ascii.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);

cin>>n;

v.push_back(make_pair(0,0));
for (int i=1;i<=n;i++)
{
 cin>>ar[i];
 if (ar[i]>0)v.push_back(make_pair(ar[i],i));
}

reach[0][5]=1;

for (int i=1;i<v.size();i++)
if (v[i].first<v[i-1].first){cout<<-1<<endl;return 0;}

for (int i=0;i+1<v.size();i++)
 {
  rspan=v[i+1].second-v[i].second;
  for (int op=1;op<=5;op++)
    for (int np=1;np<=5;np++)
     {
      if (reach[i][op]==0)continue;
      if (v[i+1].first==v[i].first&&np<=op)continue;
      if (v[i+1].first==v[i].first)
       {
        need1=need2=np-op;
       }
       else
       {
        need1=(5-op)+(v[i+1].first-v[i].first-1)*5+np;
        need2=(v[i+1].first-v[i].first-1)*2+np;
        if (op==1)need2++;

  //      cout<<need1<<" "<<need2<<endl;

       }
      if (rspan>=need2&&rspan<=need1)
      {
       reach[i+1][np]=1;
       par[i+1][np]=op;
      }
     }
 }

/*for (int i=0;i<v.size();i++)
{
    cout<<v[i].first<<"^^"<<v[i].second<<endl;
    for (int j=0;j<=5;j++)
    cout<<reach[i][j]<<" ";
    cout<<endl;
}*/

if (v[v.size()-1].second==n)reach[v.size()-1][1]=0;
if (v[v.size()-1].second==n-1)reach[v.size()-1][5]=0;
//if (v[v.size()-1].second==n-2)reach[v.size()-1][1]=0;
p=v.size()-1;

q=2;
while ((q<=5&&reach[p][q]==0))++q;
if (q==6)if (reach[p][1])q=1;
if (q==6){cout<<-1<<endl;return 0;}

/*for (int j=1;j<=5;j++)
cout<<reach[p][j]<<" ";
cout<<endl;
*/
//cout<<q<<endl; // gt t+

// tail
if (v[p].second==n-1)ar[n]=ar[n-1];
else
{
    ps=v[p].second;
    if (q==1){++ps;ar[ps]=ar[ps-1];}
    cur=ar[ps]+1;
    ++ps;
    while (ps+2<=n)
    {
     if (ps+2==n){ar[ps]=ar[ps+1]=ar[ps+2]=cur;++cur;ps+=3;}
     else{ar[ps]=ar[ps+1]=cur;cur++;ps+=2;}
    }
    if (ps<n){ar[ps]=cur;ar[ps+1]=cur;cur++;ps+=2;}
    else if (ps==n){ar[ps]=cur-1;++ps;}
}

/*
for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;
*/

for (int i=v.size()-1;i;--i)
{
    if (v[i-1].first==v[i].first){for (int j=v[i-1].second+1;j<v[i].second;j++)
    {
                                      ar[j]=ar[v[i-1].second];
    }
    q=par[i][q];continue;
    }
    else
    {
        for (int j=q;j>=1;j--)
        ar[v[i].second-q+j]=ar[v[i].second];
        tp=v[i].second-q;

        np=par[i][q];

        niters=v[i].first-v[i-1].first-1;
        for (;niters;--niters)
        {
         /*m1=(niters-1)*2;
         if (np==1)++m1;*/
         m2=(niters-1)*5+(5-np);
         qq=2;
         while (tp-qq>(v[i-1].second+m2))++qq;
         for (int j=tp-qq+1;j<=tp;j++)
          ar[j]=v[i-1].first+niters;
         tp=tp-qq;
        }
        for (int j=v[i-1].second;j<=tp;j++)
        ar[j]=v[i-1].first;

        q=np;

    }
}
cout<<ar[n]<<endl;
for (int i=1;i<=n;i++)
if (ar[i]==0)ar[i]=1;

for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;

cin.get();cin.get();
return 0;}


/*
I could not breath against the wall
The clash of light against the floor
They held me up against the wall
Too young to be ignored

Standing by a building
Leaks out information
Passive death of freedom gets me
Where's my security
Behind my back it goes
Early morning's coming
The risk that I am taking
Recall a song that I heard as a child
No more false immunity
Inside the blistering cold

My youth unknown to me
I'm walking by a wire
What's left from me to breathe
Cold smell of fire
One day I will be free
I was born to be no one
My youth unknown to me
I walked behind the sun

Emptiness within me
Exit signs within me
The one you're looking for is not here
Had no security
He will not come back
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
//#include <memory.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define  INF 100000000
#define eps 1e-13
//#define M_PI 3.141592653589793
//#define mx 1000000000000ll
#define bs 1000000007

//#define free asdfasdfsdadsg
//#define szz 400
//#define pb push_back
#define MAXN 10000
#define free afdshjioey
//#define SIZE 60
#define bsize 2000

using namespace std;

long n;
vector<pair<long, long> > v;
long ar[300000];
long reach[300000][10];
long rspan,need1,need2;
long p,q;
long par[300000][10];
long ps,cur;
long tp,np,niters,m2,m1,qq;

int main(){
//freopen("ascii.in","r",stdin);
//freopen("ascii.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);

cin>>n;

v.push_back(make_pair(0,0));
for (int i=1;i<=n;i++)
{
 cin>>ar[i];
 if (ar[i]>0)v.push_back(make_pair(ar[i],i));
}

reach[0][5]=1;

for (int i=1;i<v.size();i++)
if (v[i].first<v[i-1].first){cout<<-1<<endl;return 0;}

for (int i=0;i+1<v.size();i++)
 {
  rspan=v[i+1].second-v[i].second;
  for (int op=1;op<=5;op++)
    for (int np=1;np<=5;np++)
     {
      if (reach[i][op]==0)continue;
      if (v[i+1].first==v[i].first&&np<=op)continue;
      if (v[i+1].first==v[i].first)
       {
        need1=need2=np-op;
       }
       else
       {
        need1=(5-op)+(v[i+1].first-v[i].first-1)*5+np;
        need2=(v[i+1].first-v[i].first-1)*2+np;
        if (op==1)need2++;

  //      cout<<need1<<" "<<need2<<endl;

       }
      if (rspan>=need2&&rspan<=need1)
      {
       reach[i+1][np]=1;
       par[i+1][np]=op;
      }
     }
 }

/*for (int i=0;i<v.size();i++)
{
    cout<<v[i].first<<"^^"<<v[i].second<<endl;
    for (int j=0;j<=5;j++)
    cout<<reach[i][j]<<" ";
    cout<<endl;
}*/

if (v[v.size()-1].second==n)reach[v.size()-1][1]=0;
if (v[v.size()-1].second==n-1)reach[v.size()-1][5]=0;

p=v.size()-1;

q=1;
while (q<=5&&reach[p][q]==0)++q;
if (q==6){cout<<-1<<endl;return 0;}

//cout<<q<<endl; // gt t+

// tail
if (v[p].second==n-1)ar[n]=ar[n-1];
else
{
    ps=v[p].second;
    if (q==1){++ps;ar[ps]=ar[ps-1];}
    cur=ar[ps]+1;
    ++ps;
    while (ps+2<=n)
    {
     if (ps+2==n){ar[ps]=ar[ps+1]=ar[ps+2]=cur;++cur;ps+=3;}
     else{ar[ps]=ar[ps+1]=cur;cur++;ps+=2;}
    }
    if (ps<n){ar[ps]=cur;ar[ps+1]=cur;cur++;ps+=2;}
}

/*
for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;
*/

for (int i=v.size()-1;i;--i)
{
    if (v[i-1].first==v[i].first){for (int j=v[i-1].second+1;j<v[i].second;j++)
    {
                                      ar[j]=ar[v[i-1].second];
    }
    q=par[i][q];continue;
    }
    else
    {
        for (int j=q;j>=1;j--)
        ar[v[i].second-q+j]=ar[v[i].second];
        tp=v[i].second-q;

        np=par[i][q];

        niters=v[i].first-v[i-1].first-1;
        for (;niters;--niters)
        {
         /*m1=(niters-1)*2;
         if (np==1)++m1;*/
         m2=(niters-1)*5+(5-np);
         qq=2;
         while (tp-qq>(v[i-1].second+m2))++qq;
         for (int j=tp-qq+1;j<=tp;j++)
          ar[j]=v[i-1].first+niters;
         tp=tp-qq;
        }
        for (int j=v[i-1].second;j<=tp;j++)
        ar[j]=v[i-1].first;

        q=np;

    }
}
cout<<ar[n]<<endl;
for (int i=1;i<=n;i++)
if (ar[i]==0)ar[i]=1;

for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;

cin.get();cin.get();
return 0;}


/*
I could not breath against the wall
The clash of light against the floor
They held me up against the wall
Too young to be ignored

Standing by a building
Leaks out information
Passive death of freedom gets me
Where's my security
Behind my back it goes
Early morning's coming
The risk that I am taking
Recall a song that I heard as a child
No more false immunity
Inside the blistering cold

My youth unknown to me
I'm walking by a wire
What's left from me to breathe
Cold smell of fire
One day I will be free
I was born to be no one
My youth unknown to me
I walked behind the sun

Emptiness within me
Exit signs within me
The one you're looking for is not here
Had no security
He will not come back
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
//#include <memory.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define  INF 100000000
#define eps 1e-13
//#define M_PI 3.141592653589793
//#define mx 1000000000000ll
#define bs 1000000007

//#define free asdfasdfsdadsg
//#define szz 400
//#define pb push_back
#define MAXN 10000
#define free afdshjioey
//#define SIZE 60
#define bsize 2000

using namespace std;

long n;
vector<pair<long, long> > v;
long ar[300000];
long reach[300000][10];
long rspan,need1,need2;
long p,q;
long par[300000][10];
long ps,cur;
long tp,np,niters,m2,m1,qq;

int main(){
//freopen("ascii.in","r",stdin);
//freopen("ascii.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);

cin>>n;

v.push_back(make_pair(0,0));
for (int i=1;i<=n;i++)
{
 cin>>ar[i];
 if (ar[i]>0)v.push_back(make_pair(ar[i],i));
}

reach[0][5]=1;

for (int i=0;i+1<v.size();i++)
 {
  rspan=v[i+1].second-v[i].second;
  for (int op=1;op<=5;op++)
    for (int np=1;np<=5;np++)
     {
      if (reach[i][op]==0)continue;
      if (v[i+1].first==v[i].first&&np<=op)continue;
      if (v[i+1].first==v[i].first)
       {
        need1=need2=np-op;
       }
       else
       {
        need1=(5-op)+(v[i+1].first-v[i].first-1)*5+np;
        need2=(v[i+1].first-v[i].first-1)*2+np;
        if (op==1)need2++;

  //      cout<<need1<<" "<<need2<<endl;

       }
      if (rspan>=need2&&rspan<=need1)
      {
       reach[i+1][np]=1;
       par[i+1][np]=op;
      }
     }
 }

/*for (int i=0;i<v.size();i++)
{
    cout<<v[i].first<<"^^"<<v[i].second<<endl;
    for (int j=0;j<=5;j++)
    cout<<reach[i][j]<<" ";
    cout<<endl;
}*/

if (v[v.size()-1].second==n)reach[v.size()-1][1]=0;
if (v[v.size()-1].second==n-1)reach[v.size()-1][5]=0;

p=v.size()-1;

q=1;
while (q<=5&&reach[p][q]==0)++q;
if (q==6){cout<<-1<<endl;return 0;}

//cout<<q<<endl; // gt t+

// tail
if (v[p].second==n-1)ar[n]=ar[n-1];
else
{
    ps=v[p].second;
    if (q==1){++ps;ar[ps]=ar[ps-1];}
    cur=ar[ps]+1;
    ++ps;
    while (ps+2<=n)
    {
     if (ps+2==n){ar[ps]=ar[ps+1]=ar[ps+2]=cur;++cur;ps+=3;}
     else{ar[ps]=ar[ps+1]=cur;cur++;ps+=2;}
    }
    if (ps<n){ar[ps]=cur;ar[ps+1]=cur;cur++;ps+=2;}
}

/*
for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;
*/

for (int i=v.size()-1;i;--i)
{
    if (v[i-1].first==v[i].first){for (int j=v[i-1].second+1;j<v[i].second;j++)
    {
                                      ar[j]=ar[v[i-1].second];
    }
    q=par[i][q];continue;
    }
    else
    {
        for (int j=q;j>=1;j--)
        ar[v[i].second-q+j]=ar[v[i].second];
        tp=v[i].second-q;

        np=par[i][q];

        niters=v[i].first-v[i-1].first-1;
        for (;niters;--niters)
        {
         /*m1=(niters-1)*2;
         if (np==1)++m1;*/
         m2=(niters-1)*5+(5-np);
         qq=2;
         while (tp-qq>(v[i-1].second+m2))++qq;
         for (int j=tp-qq+1;j<=tp;j++)
          ar[j]=v[i-1].first+niters;
         tp=tp-qq;
        }
        for (int j=v[i-1].second;j<=tp;j++)
        ar[j]=v[i-1].first;
    }
}
for (int i=1;i<=n;i++)
if (ar[i]==0)ar[i]=1;

for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;

cin.get();cin.get();
return 0;}


/*
I could not breath against the wall
The clash of light against the floor
They held me up against the wall
Too young to be ignored

Standing by a building
Leaks out information
Passive death of freedom gets me
Where's my security
Behind my back it goes
Early morning's coming
The risk that I am taking
Recall a song that I heard as a child
No more false immunity
Inside the blistering cold

My youth unknown to me
I'm walking by a wire
What's left from me to breathe
Cold smell of fire
One day I will be free
I was born to be no one
My youth unknown to me
I walked behind the sun

Emptiness within me
Exit signs within me
The one you're looking for is not here
Had no security
He will not come back
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
//#include <memory.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define  INF 100000000
#define eps 1e-13
//#define M_PI 3.141592653589793
//#define mx 1000000000000ll
#define bs 1000000007

//#define free asdfasdfsdadsg
//#define szz 400
//#define pb push_back
#define MAXN 10000
#define free afdshjioey
//#define SIZE 60
#define bsize 2000

using namespace std;

long n;
vector<pair<long, long> > v;
long ar[300000];
long reach[300000][10];
long rspan,need1,need2;
long p,q;
long par[300000][10];
long ps,cur;
long tp,np,niters,m2,m1,qq;

int main(){
//freopen("ascii.in","r",stdin);
//freopen("ascii.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);

cin>>n;

v.push_back(make_pair(0,0));
for (int i=1;i<=n;i++)
{
 cin>>ar[i];
 if (ar[i]>0)v.push_back(make_pair(ar[i],i));
}

reach[0][5]=1;

for (int i=0;i+1<v.size();i++)
 {
  rspan=v[i+1].second-v[i].second;
  for (int op=1;op<=5;op++)
    for (int np=1;np<=5;np++)
     {
      if (reach[i][op]==0)continue;
      if (v[i+1].first==v[i].first&&np<=op)continue;
      if (v[i+1].first==v[i].first)
       {
        need1=need2=np-op;
       }
       else
       {
        need1=(5-op)+(v[i+1].first-v[i].first-1)*5+np;
        need2=(v[i+1].first-v[i].first-1)*2+np;
        if (op==1)need2++;

  //      cout<<need1<<" "<<need2<<endl;

       }
      if (rspan>=need2&&rspan<=need1)
      {
       reach[i+1][np]=1;
       par[i+1][np]=op;
      }
     }
 }

/*for (int i=0;i<v.size();i++)
{
    cout<<v[i].first<<"^^"<<v[i].second<<endl;
    for (int j=0;j<=5;j++)
    cout<<reach[i][j]<<" ";
    cout<<endl;
}*/

if (v[v.size()-1].second==n)reach[v.size()-1][1]=0;
if (v[v.size()-1].second==n-1)reach[v.size()-1][5]=0;

p=v.size()-1;

q=1;
while (q<=5&&reach[p][q]==0)++q;
if (q==6){cout<<-1<<endl;return 0;}

//cout<<q<<endl; // gt t+

// tail
if (v[p].second==n-1)ar[n]=ar[n-1];
else
{
    ps=v[p].second;
    if (q==1){++ps;ar[ps]=ar[ps-1];}
    cur=ar[ps]+1;
    ++ps;
    while (ps+2<=n)
    {
     if (ps+2==n){ar[ps]=ar[ps+1]=ar[ps+2]=cur;++cur;ps+=3;}
     else{ar[ps]=ar[ps+1]=cur;cur++;ps+=2;}
    }
    if (ps<n){ar[ps]=cur;ar[ps+1]=cur;cur++;ps+=2;}
}

/*
for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;
*/

for (int i=v.size()-1;i;--i)
{
    if (v[i-1].first==v[i].first){for (int j=v[i-1].second+1;j<v[i].second;j++)
    {
                                      ar[j]=ar[v[i-1].second];
    }
    q=par[i][q];continue;
    }
    else
    {
        for (int j=q;j>=1;j--)
        ar[v[i].second-q+j]=ar[v[i].second];
        tp=v[i].second-q;

        np=par[i][q];

        niters=v[i].first-v[i-1].first-1;
        for (;niters;--niters)
        {
         /*m1=(niters-1)*2;
         if (np==1)++m1;*/
         m2=(niters-1)*5+(5-np);
         qq=2;
         while (tp-qq>(v[i-1].second+m2))++qq;
         for (int j=tp-qq+1;j<=tp;j++)
          ar[j]=v[i-1].first+niters;
         tp=tp-qq;
        }
        for (int j=v[i-1].second;j<=tp;j++)
        ar[j]=v[i-1].first;
    }
}
cout<<ar[n]<<endl;
for (int i=1;i<=n;i++)
if (ar[i]==0)ar[i]=1;

for (int i=1;i<=n;i++)
{
    if (i-1)cout<<" ";
    cout<<ar[i];
}
cout<<endl;

cin.get();cin.get();
return 0;}


#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100010;

int a[N], n;

bool dp[N][6];
pair<int, int> ans[N][6];

bool Judge(int x, int y){
	if(y + y > x) return false;
	if(y + y + y + y + y < x) return false;
	return true;
}

void Work(int l, int r, int x, int y){
	if(r < l) return ;
	int k = (r - l + 1) / (y - x + 1);
	for(int i = 0, j = l; i < y - x + 1; i++){
		for(int t = 0; t < k + (i < (r - l + 1) % (y - x + 1)); t++)
			a[j++] = i + x;
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	a[0] = 0;
	dp[0][0] = 1;
	int pre = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] == 0) continue;
		if(a[i] == a[pre]){
			if(i - pre > 4)
				return puts("-1"), 0;
			for(int j = i - pre; j <= 4; j++)
				if(dp[pre][j]) dp[i][j - (i - pre)] = true, ans[i][j - (i - pre)] = make_pair(pre, j);
		}
		else{
			for(int j = 0; j <= 4; j++){
				if(dp[pre][j] == false || j + pre >= i) continue;
				for(int k = 0; k <= 4; k++){
					if(i - k - pre - j - 1 < 0) continue;
					if(Judge(i - k - pre - j - 1, a[i] - a[pre] - 1) == false) continue;
					for(int x = (k == 0); x + k <= 4; x++)
						dp[i][x] = true, ans[i][x] = make_pair(pre, j);
				}
			}
		}
		pre = i;
	}
	int ret = -1, x = -1, y = -1;
	for(int i = 0; i <= 4; i++){
		if(dp[pre][i] == false || pre + i > n) continue;
		if(pre + i == n - 1) continue;
		if(ret < a[pre] + (n - pre - i) / 2){
			ret = a[pre] + (n - pre - i) / 2;
			x = pre, y = i;
			Work(pre + i + 1, n, a[pre] + 1, a[pre] + (n - pre - i) / 2);
			break;
		}
	}
	cout << ret << endl;
	if(ret + 1){
		while(x){
			int px = ans[x][y].first;
			int py = ans[x][y].second;
			if(a[x] == a[px]){
				for(int i = px; i <= x + y; i++)
					a[i] = a[x];
			}
			else{
				for(int i = 0; i + y <= 4; i++){
					if(x - i - px - py - 1 < 0) continue;
					if(Judge(x - i - px - py - 1, a[x] - a[px] - 1) == false) continue;
					Work(px + py + 1, x - i - 1, a[px] + 1, a[x] - 1);
					for(int j = -i; j <= y; j++)
						a[j + x] = a[x];
					break;
				}
			}
			x = px;
			y = py;
		}
		for(int i = 1; i <= n; i++)
			cout << a[i] << " ";cout << endl;
	}
	return 0;
}


#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200010;

int a[N], n;

bool dp[N][6];
pair<int, int> ans[N][6];

bool Judge(int x, int y){
	if(y + y > x) return false;
	if(y + y + y + y + y < x) return false;
	return true;
}

void Work(int l, int r, int x, int y){
	if(r < l) return ;
	int k = (r - l + 1) / (y - x + 1);
	for(int i = 0, j = l; i < y - x + 1; i++){
		for(int t = 0; t < k + (i < (r - l + 1) % (y - x + 1)); t++)
			a[j++] = i + x;
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	a[0] = 0;
	dp[0][0] = 1;
	int pre = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] == 0) continue;
		if(a[i] == a[pre]){
			if(i - pre > 4)
				return puts("-1"), 0;
			for(int j = i - pre; j <= 4; j++)
				if(dp[pre][j]) dp[i][j - (i - pre)] = true, ans[i][j - (i - pre)] = make_pair(pre, j);
		}
		else{
			for(int j = 0; j <= 4; j++){
				if(dp[pre][j] == false || j + pre >= i) continue;
				for(int k = 0; k <= 4; k++){
					if(i - k - pre - j - 1 < 0) continue;
					if(Judge(i - k - pre - j - 1, a[i] - a[pre] - 1) == false) continue;
					for(int x = (k == 0); x + k <= 4; x++)
						dp[i][x] = true, ans[i][x] = make_pair(pre, j);
				}
			}
		}
		pre = i;
	}
	int ret = -1, x = -1, y = -1;
	for(int i = 0; i <= 4; i++){
		if(dp[pre][i] == false || pre + i > n) continue;
		if(pre + i == n - 1) continue;
		if(ret < a[pre] + (n - pre - i) / 2){
			ret = a[pre] + (n - pre - i) / 2;
			x = pre, y = i;
			Work(pre + i + 1, n, a[pre] + 1, a[pre] + (n - pre - i) / 2);
			break;
		}
	}
	cout << ret << endl;
	if(ret + 1){
		while(x){
			int px = ans[x][y].first;
			int py = ans[x][y].second;
			if(a[x] == a[px]){
				for(int i = px; i <= x + y; i++)
					a[i] = a[x];
			}
			else{
				for(int i = (y == 0); i + y <= 4; i++){
					if(x - i - px - py - 1 < 0) continue;
					if(Judge(x - i - px - py - 1, a[x] - a[px] - 1) == false) continue;
					Work(px + py + 1, x - i - 1, a[px] + 1, a[x] - 1);
					for(int j = -i; j <= y; j++)
						a[j + x] = a[x];
					break;
				}
			}
			x = px;
			y = py;
		}
		for(int i = 1; i <= n; i++)
			cout << a[i] << " ";cout << endl;
	}
	return 0;
}


#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100010;

int a[N], n;

bool dp[N][6];
pair<int, int> ans[N][6];

bool Judge(int x, int y){
	if(y + y > x) return false;
	if(y + y + y + y + y < x) return false;
	return true;
}

void Work(int l, int r, int x, int y){
	if(r < l) return ;
	int k = (r - l + 1) / (y - x + 1);
	for(int i = 0, j = l; i < y - x + 1; i++){
		for(int t = 0; t < k + (i < (r - l + 1) % (y - x + 1)); t++)
			a[j++] = i + x;
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	a[0] = 0;
	dp[0][0] = 1;
	int pre = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] == 0) continue;
		if(a[i] == a[pre]){
			if(i - pre > 4)
				return puts("-1"), 0;
			for(int j = i - pre; j <= 4; j++)
				if(dp[pre][j]) dp[i][j - (i - pre)] = true, ans[i][j - (i - pre)] = make_pair(pre, j);
		}
		else{
			for(int j = 0; j <= 4; j++){
				if(dp[pre][j] == false || j + pre >= i) continue;
				for(int k = 0; k <= 4; k++){
					if(i - k - pre - j - 1 < 0) continue;
					if(Judge(i - k - pre - j - 1, a[i] - a[pre] - 1) == false) continue;
					for(int x = (k == 0); x + k <= 4; x++)
						dp[i][x] = true, ans[i][x] = make_pair(pre, j);
				}
			}
		}
		pre = i;
	}
	int ret = -1, x = -1, y = -1;
	for(int i = 0; i <= 4; i++){
		if(dp[pre][i] == false || pre + i > n) continue;
		if(pre + i == n - 1) continue;
		if(ret < a[pre] + (n - pre - i) / 2){
			ret = a[pre] + (n - pre - i) / 2;
			x = pre, y = i;
			Work(pre + i + 1, n, a[pre] + 1, a[pre] + (n - pre - i) / 2);
			break;
		}
	}
	cout << ret << endl;
	if(ret + 1){
		while(x){
			int px = ans[x][y].first;
			int py = ans[x][y].second;
			if(a[x] == a[px]){
				for(int i = px; i <= x + y; i++)
					a[i] = a[x];
			}
			else{
				for(int i = (y == 0); i + y <= 4; i++){
					if(x - i - px - py - 1 < 0) continue;
					if(Judge(x - i - px - py - 1, a[x] - a[px] - 1) == false) continue;
					Work(px + py + 1, x - i - 1, a[px] + 1, a[x] - 1);
					for(int j = -i; j <= y; j++)
						a[j + x] = a[x];
					break;
				}
			}
			x = px;
			y = py;
		}
		for(int i = 1; i <= n; i++)
			cout << a[i] << " ";cout << endl;
	}
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
pair <int,int> l[200010],r[200010];
int a[200010],c[200010];
void work(int n)
{
    if (a[1]>1)
    {
        printf("-1\n");
        return;
    }
    l[1]=r[1]=make_pair(1,1);
    for (int i=2;i<=n;i++)
    {
        l[i]=l[i-1].second>=2?make_pair(l[i-1].first+1,1):make_pair(l[i-1].first,l[i-1].second+1);
        r[i]=r[i-1].second==5?make_pair(r[i-1].first+1,1):make_pair(r[i-1].first,r[i-1].second+1);
        if (a[i]!=0)
        {
            if (l[i].first<a[i] || r[i].first>a[i])
            {
                printf("-1\n");
                return;
            }
            l[i]=min(l[i],make_pair(a[i],5));
            r[i]=max(r[i],make_pair(a[i],1));
        }
    }
    pair <int,int> ans=l[n];
    if (ans.second==1)
        ans=make_pair(l[n].first-1,5);
    if (ans<r[n])
    {
        printf("-1\n");
        return;
    }
    printf("%d\n",ans.first);
    a[n]=ans.first;
    c[a[n]]=1;
    for (int i=n-1;i;i--)
    {
        a[i]=min(a[i+1],l[i].first);
        if (c[a[i]]==5)
            a[i]--;
        c[a[i]]++;
    }
    for (int i=1;i<=n;i++)
        printf("%d%c",a[i],i==n?'\n':' ');
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    work(n);
    return(0);
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[100005];
int ret[100005],cnt[100005];
P lb[100005],ub[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=min(ub[i],mp(a[i],5));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1; printf("%d\n",ans.f);
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d%c",ret[i],i==n?'\n':' ');
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[200005];
int ret[200005],cnt[200005];
P lb[200005],ub[200005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=min(ub[i],mp(a[i],2));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1; printf("%d\n",ans.f);
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d%c",ret[i],i==n?'\n':' ');
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[100005];
int ret[100005],cnt[100005];
P lb[100005],ub[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=max(ub[i],mp(a[i],5));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1;
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d ",ret[i]);
	puts("");
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[100005];
int ret[100005],cnt[100005];
P lb[100005],ub[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=max(ub[i],mp(a[i],5));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1;
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d",ret[i]);
	puts("");
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[100005];
int ret[100005],cnt[100005];
P lb[100005],ub[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=min(ub[i],mp(a[i],5));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1; printf("%d\n",ret[n]);
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d ",ret[i]);
	puts("");
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[200005];
int ret[200005],cnt[200005];
P lb[200005],ub[200005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=min(ub[i],mp(a[i],INF));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=INF;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1; printf("%d\n",ans.f);
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d%c",ret[i],i==n?'\n':' ');
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[200005];
int ret[200005],cnt[200005];
P lb[200005],ub[200005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=min(ub[i],mp(a[i],5));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1; printf("%d\n",ans.f);
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d%c",ret[i],i==n?'\n':' ');
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[100005];
int ret[100005],cnt[100005];
P lb[100005],ub[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(num[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=max(ub[i],mp(a[i],5));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1;
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d",ret[i]);
	puts("");
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[100005];
int ret[100005],cnt[100005];
P lb[100005],ub[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=max(ub[i],mp(a[i],5));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1; printf("%d\n",ret[n]);
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d ",ret[i]);
	puts("");
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int a[100005];
int ret[100005],cnt[100005];
P lb[100005],ub[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]>1) return puts("-1");
	lb[1]=ub[1]=mp(1,1);
	for(int i=2;i<=n;i++)
	{
		lb[i]=lb[i-1];
		lb[i].s++;
		ub[i]=ub[i-1];
		ub[i].s++;
		if(lb[i].s>5)
		{
			lb[i].f++;
			lb[i].s=1;
		}
		if(ub[i].s>2)
		{
			ub[i].f++;
			ub[i].s=1;
		}
		if(a[i])
		{
			if(!(lb[i].f<=a[i] && a[i]<=ub[i].f))
			{
				return puts("-1");
			}
			lb[i]=max(lb[i],mp(a[i],1));
			ub[i]=min(ub[i],mp(a[i],2));
		}

	}
	P ans=ub[n];
	if(ans.s==1)
	{
		ans.f--;
		ans.s=5;
	}
	if(ans<lb[n]) return puts("-1");
	ret[n]=ans.f;
	cnt[ans.f]=1; printf("%d\n",ans.f);
	for(int i=n-1;i>=1;i--)
	{
		ret[i]=min(ret[i+1],ub[i].f);
		if(cnt[ret[i]]==5)
		{
			ret[i]--;
		}
		cnt[ret[i]]++;
	}
	for(int i=1;i<=n;i++) printf("%d%c",ret[i],i==n?'\n':' ');
}


# include <iostream>
# include <cstdio>
using namespace std;

typedef pair<int,int> pii;
#define x first
#define y second
const int maxn = 200005;
pii L[maxn], R[maxn];
int cnt[maxn], a[maxn], n;

int main() {
	ios::sync_with_stdio(0);
	int n; cin >> n;
	for(int i=0; i<n; i++) cin>>a[i];
	if(a[0]>1) return cout<<-1<<endl,0;

	L[0]=R[0]=make_pair(1,1);
	for(int i=1;i<n;i++) {
		L[i] = L[i-1]; L[i].y++; R[i] = R[i-1]; R[i].y++;
		if(L[i].y>5) L[i].x++, L[i].y=1;
		if(R[i].y>2) R[i].x++, R[i].y=1;
		if(a[i] && (L[i].x>a[i] || R[i].x<a[i]))
			return cout << -1 << endl, 0;
		if(a[i]) L[i]=max(L[i],make_pair(a[i],1));
		if(a[i]) R[i]=min(R[i],make_pair(a[i],5));
	}

	pii ans = R[n-1];
	if(ans.y == 1) ans.x--, ans.y=5;
	if(ans < L[n-1]) return cout<<-1<<endl,0;

	cout << ans.x << endl;
	a[n-1] = ans.x; cnt[ans.x] = 1;
	for(int i=n-2; i>=0; i--) {
		a[i] = min(a[i+1], R[i].first);
		if(cnt[a[i]] == 5) a[i]--;
		cnt[a[i]]++;
	}
	for(int i=0; i<n; i++) cout << a[i] << ' ';
	cout << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ms0(x) memset(x,0,sizeof(x))
#define ms1(x) memset(x,-1,sizeof(x))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define f first
#define s second
#define inf 1001001001
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9;
int a,s[200005],fl=0,dpl[200005],dpr[200005],dpv[200005];
int c[200005];
int call(int i,int d,int e)
{
   if(c[e]!=-1)
    return e;
   // cout<<e<<"s ";
    int l,r,rmx,p,cnt,rm,n,j,k,R,L,ll,dd,m,b;
    R=e-d*2;L=e-d*5;

    if((L>dpl[i]+5)||(R<=dpr[i]))
    return -1;
    if(i==0)
    return 1;

    r=max(dpr[i],L-1);
    ll=r-4;
    ll=max(ll,dpr[i-1]+1);
    dd=dpv[i]-dpv[i-1]-1;
    fl=0;
   for(j=ll;j<=dpl[i];j++)
    {
        //cout<<j<<endl;
       n=call(i-1,dd,j);
      // cout<<n<<" ";
       if(n>-1)
       {
           if(j==r)
           r++;
           if(r>=R)
           continue;

           /*if(c[i]==-1)
           c[i]=a;
           else
           a=c[i];*/
           c[e]=1;
           p=dpv[i];

          // cout<<e<<endl;
           while(j<=r)
           {
               s[a]=p;
               j++;a++;
               //cout<<p<<",";
           }
           cnt=e-r-1;
           if(d>0)
           {
               m=cnt/d;
               rm=cnt%d;
               for(k=0;k<d;k++)
               {
                   p++;
                   for(b=0;b<m;b++)
                   {
                       s[a]=p;
                       a++;
                      // cout<<p<<".";
                   }
                   if(rm>0)
                   {s[a]=p;
                  // cout<<p<<".";
                   rm--;
                   a++;
                   }
               }
           }
           //fl++;
           //cout<<",,"<<fl<<endl;
           return e;
       }

    }
    return -1;
}
void pr(int cnt,int p)
{
    int m,rm,k,b;
    m=cnt/2;
               rm=cnt%2;
               for(k=0;k<m;k++)
               {
                   p++;
                   for(b=0;b<2;b++)
                   {
                       s[a]=p;
                       a++;
                   }
                   if(rm>0)
                   {s[a]=p;
                   rm--;
                   a++;
                   }
               }

}
int main()
{
    ms1(c);
    int k=0,n,i,m,l,r,d,p,cnt,j,rm,b,flag=0;
    a=0;
    cin>>n;

    dpl[0]=0;dpr[0]=0;dpv[0]=0;
    cin>>m;
    if(m<=1)
    {

               k++;
               dpl[k]=1;dpr[k]=1;dpv[k]=1;
    }
    else
    {
        cout<<-1;
        return 0;
    }
    for(i=1;i<n;i++)
    {
        cin>>m;
        if(m>0)
        {
            if(dpv[k]==m)
            {
                dpr[k]=i+1;
                if(dpr[k]-dpl[k]>=5)
                {
                    cout<<-1;
                    return 0;
                }
            }
            else
            {

               k++;
               dpl[k]=i+1;
               dpr[k]=i+1;
               dpv[k]=m;
            }
        }
    }
    for(j=1;j<=k;j++)
    if(dpr[j]-dpr[j-1]==1&&dpr[j+1]-dpr[j]>1)
    {
        dpr[j]++;
    }
    if(dpr[k]+1==n)
    dpr[k]++;
    if(dpr[k]-dpl[k]>=5)
    {
        cout<<-1;
        return 0;
    }
    else if(k==0)
    {pr(n,0);
    flag=1;
    }
    else
    {
        d=dpv[k]-dpv[k-1]-1;
        l=max(dpr[k-1]+1,dpr[k]-4);
        while(l<=dpl[k])
        {
            m=call(k-1,d,l);
            //cout<<m<<endl;
            if(m>-1)
            {
                r=dpr[k];
                if(l==r)
                {
                    if(n>r)
                    r++;
                    else
                    {
                        cout<<-1;
                        return 0;
                    }
                }
                cnt=n-r;
                if(cnt==1)
                r++;
                if(r-l>4)
                {
                    cout<<-1;
                    return 0;
                }
                p=dpv[k];
                while(l<=r)
                {
                  s[a]=p;
                  l++;a++;
                }
                pr(cnt,p);
                flag=1;
               break;
            }
            l++;
        }

    }
    if(flag==0)
    {
        cout<<-1;
        return 0;
    }

    cout<<s[a-1]<<endl;

    for(i=0;i<a;i++)
    cout<<s[i]<<" ";

    return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
pair <int,int> l[200010],r[200010];
int a[200010];
void work(int n)
{
    if (a[1]>1)
    {
        printf("-1\n");
        return;
    }
    l[1]=r[1]=make_pair(1,1);
    for (int i=2;i<=n;i++)
    {
        l[i]=l[i-1].second>=2?make_pair(l[i-1].first+1,1):make_pair(l[i-1].first,l[i-1].second+1);
        r[i]=r[i-1].second==5?make_pair(r[i-1].first+1,1):make_pair(r[i-1].first,r[i-1].second+1);
        if (a[i]!=0)
        {
            if (l[i].first<a[i] || r[i].first>a[i])
            {
                printf("-1\n");
                return;
            }
            l[i]=min(l[i],make_pair(a[i],5));
            r[i]=max(r[i],make_pair(a[i],1));
        }
    }
    pair <int,int> ans=l[n];
    if (ans.second==1)
        ans=make_pair(l[n].first-1,5);
    if (ans<r[n])
    {
        printf("-1\n");
        return;
    }
    printf("%d\n",ans.first);
    a[n]=ans.first;
    for (int i=n-1;i;i--)
        a[i]=min(a[i+1],l[i].first);
    for (int i=1;i<=n;i++)
        printf("%d%c",a[i],i==n?'\n':' ');
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    work(n);
    return(0);
}


#include<iostream>
using namespace std;
int a[200010],cnt[100002],n;
pair<int,int> Max[200010],Min[200010];

int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	if(a[1]>1)  cout<<"-1"<<endl;
	else{
		bool flag=1;
		Max[1]=Min[1]=make_pair(1,1);
		for(int i=2;i<=n&&flag;++i)
		{
			if(Max[i-1].second>=2)  Max[i]=make_pair(Max[i-1].first+1,1);
			else Max[i]=make_pair(Max[i-1].first,Max[i-1].second+1);
      		                            	          // 上一本书数目大于2。能过，不断地加 112233  小于二，则添加
			if(Min[i-1].second==5)  Min[i]=make_pair(Min[i-1].first+1,1);
			else Min[i]=make_pair(Min[i-1].first,Min[i-1].second+1);
			                                          //  i[1]=5  满书，放下一个   111112222233333
			if(a[i]){
				if(a[i]<Min[i].first || a[i]>Max[i].first) flag=0;                //cout<<"\1"<<endl;}
				else{
					Max[i]=min(Max[i],make_pair(a[i],5));
					Min[i]=max(Min[i],make_pair(a[i],1));
				}  // 状态转移
			}
		}
		if(flag)
		{
			pair<int,int> ans = Max[n];
			if(ans.second==1)  ans=make_pair(ans.first-1,5);  // 最后一天要大于等于2
			if(ans<Min[n])  cout<<-1<<endl;
			else{
				cout<<ans.first<<endl;
				a[n]=ans.first;
				cnt[a[n]]=1;
				for(int i=n-1;i;--i)
				{
					a[i]=min(Max[i].first,a[i+1]);
					if(cnt[a[i]]==5)  a[i]--;
					cnt[a[i]]++;
				}
				for(int i=1;i<=n;++i)
					cout<<a[i]<<' ';
				cout<<endl;
			}
		}
		else cout<<-1<<endl;
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std ;

#define MAXN 200007

int n ;
int k ;
int a[ MAXN ] ;

int dp[ MAXN ][ 7 ] ;
int prv[ MAXN ][ 7 ] ;
int ans[ MAXN ] ;

struct tuhla {
	int l , r ;
    int val ;
};

vector < struct tuhla > v ;
int tot ;

void paint_interval ( int l , int r , int st , int br ) {
	//printf ( "%d %d %d %d\n" , l , r , st , br ) ;
    if ( n == 200000 ) {
    	if ( l <= 2485 && r <= 2485 ) {
			printf ( "%d %d %d %d\n" , l , r , st , br ) ;
        }
    }
	int i ;
    for ( i = l ; i <= r ; i ++ ) {
    	if ( st > br ) {
        	ans[ i ] = ans[ i - 1 ] ;
            continue ;
        }
    	if ( ( i - l ) % 2 == 0 ) {
        	ans[ i ] = st ;
            st ++ ;
        }
        else {
        	ans[ i ] = a[ i - 1 ] ;
        }
    }
}
void paint_range ( int l , int r , int val ) {
	int i ;
    for ( i = l ; i <= r ; i ++ ) {
    	ans[ i ] = val ;
    }
}

bool getdp ( int id , int r ) {
	//printf ( "%d %d\n" , id , r ) ;
	if ( id == 0 ) {
    	int pr = v[ id ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
           	//printf ( " YYYY %d %d\n" , pr , ( i - 1 ) ) ;
        	if ( 2 * pr <= ( i - 1 ) && ( i - 1 ) <= 5 * pr ) {
            	if ( i - 1 >= 1 ) { paint_interval ( 1 , i - 1 , 1 , pr ) ; }
                paint_range ( i , r , v[ id ].val ) ;
                if ( k == 1 ) {
					for ( t = r + 1 ; t < n ; t ++ ) {
						if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
						else { ans[ t ] = v[ id ].val ; }
					}
					if ( r != n ) { ans[ n ] = v[ id ].val ; }
					printf ( "%d\n" , ans[ n ] ) ;
					for ( t = 1 ; t <= n ; t ++ ) {
						printf ( "%d" , ans[ t ] ) ;
						if ( t == n ) { printf ( "\n" ) ; }
						else { printf ( " " ) ; }
					}
					exit ( 0 ) ;
                }
                return true ;
            }
        }
    }
    else {
    	int pr = v[ id ].val - v[ id - 1 ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
            //printf ( "~~ %d\n" , i ) ;
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
            for ( j = v[ id - 1 ].r ; j <= v[ id - 1 ].l + 4 ; j ++ ) {
            	//printf ( "   ### %d %d\n" , i , j ) ;
            	if ( a[ j ] != 0 && a[ j ] != v[ id - 1 ].val ) { continue ; }
                if ( j >= i ) { continue ; }
                int len = ( i - j - 1 ) ;
        		if ( ( 2 * pr <= len && len <= 5 * pr ) && getdp ( id - 1 , j ) == true ) {
            		if ( j + 1 <= i - 1 ) { paint_interval ( j + 1 , i - 1 , v[ id - 1 ].val + 1 , v[ id ].val - 1 ) ; }
                	paint_range ( i , r , v[ id ].val ) ;
                    if ( id == k - 1 ) {
                    	for ( t = r + 1 ; t < n ; t ++ ) {
                        	if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
                            else { ans[ t ] = v[ id ].val ; }
                        }
                        if ( r != n ) { ans[ n ] = v[ id ].val ; }
                        int br = 0 ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	if ( ans[ t ] == 0 ) { br ++ ;  }
                        }
                        if ( n == 200000 ) { printf ( "TOTAL WRONG --> %d\n" , br ) ; }
                        printf ( "%d\n" , ans[ n ] ) ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	printf ( "%d" , ans[ t ] ) ;
	                        if ( t == n ) { printf ( "\n" ) ; }
                            else { printf ( " " ) ; }
                        }
						exit ( 0 ) ;
                    }
    	            return true ;
	            }
            }
        }
    }
    return false ;
}

void input ( ) {
	scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
	int i , j , t ;
    int lst = 0 ;
    int pos = 0 ;
    vector < pair < int , int > > u ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) {
        	if ( lst != 0 && lst > a[ i ] ) { printf ( "-1\n" ) ; return ; }
        	if ( lst != 0 && lst == a[ i ] ) {
            	for ( j = pos ; j <= i ; j ++ ) {
                	a[ j ] = a[ i ] ;
                }
            }
            lst = a[ i ] ;
            pos = i ;
        }
    }
    if ( lst == 0 ) {
		for ( i = 1 ; i <= n ; i ++ ) {
        	if ( i % 2 == 1 ) { ans[ i ] = ( i / 2 + 1 ) ; }
            else { ans[ i ] = ans[ i - 1 ] ; }
        }
        if ( ans[ n ] != ans[ n - 1 ] ) { ans[ n ] = ans[ n - 1 ] ; }
        printf ( "%d\n" , ans[ n ] ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
        	printf ( "%d" , ans[ i ] ) ;
	        if ( i == n ) { printf ( "\n" ) ; }
            else { printf ( " " ) ; }
        }
		return ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) { u.push_back ( make_pair ( a[ i ] , i ) ) ; }
    }
    int br = 1 ;
    int mx = 0 ;
    int sz = u.size ( ) ;
    struct tuhla w ;
	for ( i = 1 ; i < sz ; i ++ ) {
    	if ( u[ i ].first == u[ i - 1 ].first ) { br ++ ; }
        else {
        	if ( mx < br ) { mx = br ; }
            w.r = u[ i - 1 ].second ;
            w.l = u[ i - br ] .second ;
            w.val = a[ u[ i - 1 ].second ] ;
            v.push_back ( w ) ;
            br = 1 ;
        }
    }
	if ( mx < br ) { mx = br ; }

	w.r = u[ i - 1 ].second ;
	w.l = u[ i - br ] .second ;
	w.val = a[ u[ i - 1 ].second ] ;
	v.push_back ( w ) ;
    if ( mx > 5 ) { printf ( "-1\n" ) ; return ; }
	k = v.size ( ) ;
    /**
	for ( i = 0 ; i < k ; i ++ ) {
    	//printf ( "--- %d %d %d\n" , v[ i ].l , v[ i ].r , v[ i ].val ) ;
        if ( a[ v[ i ].l ] != a[ v[ i ].r ] ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].l ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].r ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
    }
	**/
    if ( n == 200000 ) { printf ( "---- %d\n" , k ) ; }
    for ( i = 0 ; i < 5 ; i ++ ) {
    	if ( v[ ( k - 1 ) ].r + i == ( n - 1 ) ) { continue ; }
    	if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
    	if ( ( v[ ( k - 1 ) ].r - v[ ( k - 1 ) ].l + 1 ) + i > 5 ) { break ; }
        if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
		getdp ( k - 1 , v[ ( k - 1 ) ].r + i ) ;
    }
    printf ( "-1\n" ) ;
}

int main ( ) {
	ios::sync_with_stdio ( false ) ;
	cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std ;

#define MAXN 200007

int n ;
int k ;
int a[ MAXN ] ;

int dp[ MAXN ][ 7 ] ;
int prv[ MAXN ][ 7 ] ;
int ans[ MAXN ] ;

struct tuhla {
	int l , r ;
    int val ;
};

vector < struct tuhla > v ;
int tot ;

void paint_interval ( int lo , int hi , int beg , int en ) {
	//printf ( "%d %d %d %d\n" , l , r , st , br ) ;
   	/**
    if ( n == 200000 ) {
    	if ( lo <= 2485 && hi >= 2485 ) {
			printf ( "%d %d %d %d\n" , lo , hi , beg , en ) ;
        }
    }
	**/
	int i , j , t ;
	i = lo ;
    while ( 1 ) {
    	if ( i > n ) { return ; }
		for ( j = 2 ; j <= 5 ; j ++ ) {
        	int lft = ( ( hi - i + 1 ) - j ) ;
            int pr = en - beg ;
            if ( 2 * pr <= lft && lft <= 5 * pr ) {
            	break ;
            }
        }
        for ( t = 0 ; t < j ; t ++ ) {
        	ans[ i + t ] = beg ;
        }
        beg ++ ;
        i += j ;
    }
}
void paint_range ( int l , int r , int val ) {
	int i ;
    /**
    if ( n == 200000 ) {
    	if ( l <= 2485 && r >= 2485 ) {
			printf ( "%d %d %d\n" , l , r , val ) ;
        }
    }
	**/
    for ( i = l ; i <= r ; i ++ ) {
    	ans[ i ] = val ;
    }
}

bool getdp ( int id , int r ) {
	//printf ( "%d %d\n" , id , r ) ;
	if ( id == 0 ) {
    	int pr = v[ id ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
           	//printf ( " YYYY %d %d\n" , pr , ( i - 1 ) ) ;
        	if ( 2 * pr <= ( i - 1 ) && ( i - 1 ) <= 5 * pr ) {
            	if ( i - 1 >= 1 ) { paint_interval ( 1 , i - 1 , 1 , pr ) ; }
                paint_range ( i , r , v[ id ].val ) ;
                if ( k == 1 ) {
					for ( t = r + 1 ; t < n ; t ++ ) {
						if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
						else { ans[ t ] = v[ id ].val ; }
					}
					if ( r != n ) { ans[ n ] = v[ id ].val ; }
					printf ( "%d\n" , ans[ n ] ) ;
					for ( t = 1 ; t <= n ; t ++ ) {
						printf ( "%d" , ans[ t ] ) ;
						if ( t == n ) { printf ( "\n" ) ; }
						else { printf ( " " ) ; }
					}
					exit ( 0 ) ;
                }
                return true ;
            }
        }
    }
    else {
    	int pr = v[ id ].val - v[ id - 1 ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
            //printf ( "~~ %d\n" , i ) ;
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
            for ( j = v[ id - 1 ].r ; j <= v[ id - 1 ].l + 4 ; j ++ ) {
            	//printf ( "   ### %d %d\n" , i , j ) ;
            	if ( a[ j ] != 0 && a[ j ] != v[ id - 1 ].val ) { continue ; }
                if ( j >= i ) { continue ; }
                int len = ( i - j - 1 ) ;
        		if ( ( 2 * pr <= len && len <= 5 * pr ) && getdp ( id - 1 , j ) == true ) {
            		if ( j + 1 <= i - 1 ) { paint_interval ( j + 1 , i - 1 , v[ id - 1 ].val + 1 , v[ id ].val - 1 ) ; }
                	paint_range ( i , r , v[ id ].val ) ;
                    if ( id == k - 1 ) {
                    	for ( t = r + 1 ; t < n ; t ++ ) {
                        	if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
                            else { ans[ t ] = v[ id ].val ; }
                        }
                        if ( r != n ) { ans[ n ] = v[ id ].val ; }
                        /**
                        int br = 0 ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	if ( ans[ t ] == 0 ) { br ++ ;  }
                        }
						**/
                        //if ( n == 200000 ) { printf ( "TOTAL WRONG --> %d\n" , br ) ; }
                        printf ( "%d\n" , ans[ n ] ) ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	printf ( "%d" , ans[ t ] ) ;
	                        if ( t == n ) { printf ( "\n" ) ; }
                            else { printf ( " " ) ; }
                        }
						exit ( 0 ) ;
                    }
    	            return true ;
	            }
            }
        }
    }
    return false ;
}

void input ( ) {
	scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
	int i , j , t ;
    int lst = 0 ;
    int pos = 0 ;
    vector < pair < int , int > > u ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) {
        	if ( lst != 0 && lst > a[ i ] ) { printf ( "-1\n" ) ; return ; }
        	if ( lst != 0 && lst == a[ i ] ) {
            	for ( j = pos ; j <= i ; j ++ ) {
                	a[ j ] = a[ i ] ;
                }
            }
            lst = a[ i ] ;
            pos = i ;
        }
    }
    if ( lst == 0 ) {
		for ( i = 1 ; i <= n ; i ++ ) {
        	if ( i % 2 == 1 ) { ans[ i ] = ( i / 2 + 1 ) ; }
            else { ans[ i ] = ans[ i - 1 ] ; }
        }
        if ( ans[ n ] != ans[ n - 1 ] ) { ans[ n ] = ans[ n - 1 ] ; }
        printf ( "%d\n" , ans[ n ] ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
        	printf ( "%d" , ans[ i ] ) ;
	        if ( i == n ) { printf ( "\n" ) ; }
            else { printf ( " " ) ; }
        }
		return ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) { u.push_back ( make_pair ( a[ i ] , i ) ) ; }
    }
    int br = 1 ;
    int mx = 0 ;
    int sz = u.size ( ) ;
    struct tuhla w ;
	for ( i = 1 ; i < sz ; i ++ ) {
    	if ( u[ i ].first == u[ i - 1 ].first ) { br ++ ; }
        else {
        	if ( mx < br ) { mx = br ; }
            w.r = u[ i - 1 ].second ;
            w.l = u[ i - br ] .second ;
            w.val = a[ u[ i - 1 ].second ] ;
            v.push_back ( w ) ;
            br = 1 ;
        }
    }
	if ( mx < br ) { mx = br ; }

	w.r = u[ i - 1 ].second ;
	w.l = u[ i - br ] .second ;
	w.val = a[ u[ i - 1 ].second ] ;
	v.push_back ( w ) ;
    if ( mx > 5 ) { printf ( "-1\n" ) ; return ; }
	k = v.size ( ) ;
    /**
	for ( i = 0 ; i < k ; i ++ ) {
    	//printf ( "--- %d %d %d\n" , v[ i ].l , v[ i ].r , v[ i ].val ) ;
        if ( a[ v[ i ].l ] != a[ v[ i ].r ] ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].l ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].r ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
    }
    if ( n == 200000 ) { printf ( "---- %d\n" , k ) ; }
	**/

    for ( i = 0 ; i < 5 ; i ++ ) {
    	if ( v[ ( k - 1 ) ].r + i == ( n - 1 ) ) { continue ; }
    	if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
    	if ( ( v[ ( k - 1 ) ].r - v[ ( k - 1 ) ].l + 1 ) + i > 5 ) { break ; }
        if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
		getdp ( k - 1 , v[ ( k - 1 ) ].r + i ) ;
    }
    printf ( "-1\n" ) ;
}

int main ( ) {
	ios::sync_with_stdio ( false ) ;
	cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std ;

#define MAXN 200007

int n ;
int k ;
int a[ MAXN ] ;

int dp[ MAXN ][ 7 ] ;
int prv[ MAXN ][ 7 ] ;
int ans[ MAXN ] ;

struct tuhla {
	int l , r ;
    int val ;
};

vector < struct tuhla > v ;
int tot ;

void paint_interval ( int l , int r , int st , int br ) {
	//printf ( "%d %d %d %d\n" , l , r , st , br ) ;
    if ( n == 200000 ) {
    	if ( l <= 2485 && r <= 2485 ) {
			printf ( "%d %d %d %d\n" , l , r , st , br ) ;
        }
    }
	int i ;
    for ( i = l ; i <= r ; i ++ ) {
    	if ( st > br ) {
        	ans[ i ] = ans[ i - 1 ] ;
            continue ;
        }
    	if ( ( i - l ) % 2 == 0 ) {
        	ans[ i ] = st ;
            st ++ ;
        }
        else {
        	ans[ i ] = a[ i - 1 ] ;
        }
    }
}
void paint_range ( int l , int r , int val ) {
	int i ;
    if ( n == 200000 ) {
    	if ( l <= 2485 && r <= 2485 ) {
			printf ( "%d %d %d\n" , l , r , val ) ;
        }
    }
    for ( i = l ; i <= r ; i ++ ) {
    	ans[ i ] = val ;
    }
}

bool getdp ( int id , int r ) {
	//printf ( "%d %d\n" , id , r ) ;
	if ( id == 0 ) {
    	int pr = v[ id ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
           	//printf ( " YYYY %d %d\n" , pr , ( i - 1 ) ) ;
        	if ( 2 * pr <= ( i - 1 ) && ( i - 1 ) <= 5 * pr ) {
            	if ( i - 1 >= 1 ) { paint_interval ( 1 , i - 1 , 1 , pr ) ; }
                paint_range ( i , r , v[ id ].val ) ;
                if ( k == 1 ) {
					for ( t = r + 1 ; t < n ; t ++ ) {
						if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
						else { ans[ t ] = v[ id ].val ; }
					}
					if ( r != n ) { ans[ n ] = v[ id ].val ; }
					printf ( "%d\n" , ans[ n ] ) ;
					for ( t = 1 ; t <= n ; t ++ ) {
						printf ( "%d" , ans[ t ] ) ;
						if ( t == n ) { printf ( "\n" ) ; }
						else { printf ( " " ) ; }
					}
					exit ( 0 ) ;
                }
                return true ;
            }
        }
    }
    else {
    	int pr = v[ id ].val - v[ id - 1 ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
            //printf ( "~~ %d\n" , i ) ;
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
            for ( j = v[ id - 1 ].r ; j <= v[ id - 1 ].l + 4 ; j ++ ) {
            	//printf ( "   ### %d %d\n" , i , j ) ;
            	if ( a[ j ] != 0 && a[ j ] != v[ id - 1 ].val ) { continue ; }
                if ( j >= i ) { continue ; }
                int len = ( i - j - 1 ) ;
        		if ( ( 2 * pr <= len && len <= 5 * pr ) && getdp ( id - 1 , j ) == true ) {
            		if ( j + 1 <= i - 1 ) { paint_interval ( j + 1 , i - 1 , v[ id - 1 ].val + 1 , v[ id ].val - 1 ) ; }
                	paint_range ( i , r , v[ id ].val ) ;
                    if ( id == k - 1 ) {
                    	for ( t = r + 1 ; t < n ; t ++ ) {
                        	if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
                            else { ans[ t ] = v[ id ].val ; }
                        }
                        if ( r != n ) { ans[ n ] = v[ id ].val ; }
                        int br = 0 ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	if ( ans[ t ] == 0 ) { br ++ ;  }
                        }
                        if ( n == 200000 ) { printf ( "TOTAL WRONG --> %d\n" , br ) ; }
                        printf ( "%d\n" , ans[ n ] ) ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	printf ( "%d" , ans[ t ] ) ;
	                        if ( t == n ) { printf ( "\n" ) ; }
                            else { printf ( " " ) ; }
                        }
						exit ( 0 ) ;
                    }
    	            return true ;
	            }
            }
        }
    }
    return false ;
}

void input ( ) {
	scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
	int i , j , t ;
    int lst = 0 ;
    int pos = 0 ;
    vector < pair < int , int > > u ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) {
        	if ( lst != 0 && lst > a[ i ] ) { printf ( "-1\n" ) ; return ; }
        	if ( lst != 0 && lst == a[ i ] ) {
            	for ( j = pos ; j <= i ; j ++ ) {
                	a[ j ] = a[ i ] ;
                }
            }
            lst = a[ i ] ;
            pos = i ;
        }
    }
    if ( lst == 0 ) {
		for ( i = 1 ; i <= n ; i ++ ) {
        	if ( i % 2 == 1 ) { ans[ i ] = ( i / 2 + 1 ) ; }
            else { ans[ i ] = ans[ i - 1 ] ; }
        }
        if ( ans[ n ] != ans[ n - 1 ] ) { ans[ n ] = ans[ n - 1 ] ; }
        printf ( "%d\n" , ans[ n ] ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
        	printf ( "%d" , ans[ i ] ) ;
	        if ( i == n ) { printf ( "\n" ) ; }
            else { printf ( " " ) ; }
        }
		return ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) { u.push_back ( make_pair ( a[ i ] , i ) ) ; }
    }
    int br = 1 ;
    int mx = 0 ;
    int sz = u.size ( ) ;
    struct tuhla w ;
	for ( i = 1 ; i < sz ; i ++ ) {
    	if ( u[ i ].first == u[ i - 1 ].first ) { br ++ ; }
        else {
        	if ( mx < br ) { mx = br ; }
            w.r = u[ i - 1 ].second ;
            w.l = u[ i - br ] .second ;
            w.val = a[ u[ i - 1 ].second ] ;
            v.push_back ( w ) ;
            br = 1 ;
        }
    }
	if ( mx < br ) { mx = br ; }

	w.r = u[ i - 1 ].second ;
	w.l = u[ i - br ] .second ;
	w.val = a[ u[ i - 1 ].second ] ;
	v.push_back ( w ) ;
    if ( mx > 5 ) { printf ( "-1\n" ) ; return ; }
	k = v.size ( ) ;
    /**
	for ( i = 0 ; i < k ; i ++ ) {
    	//printf ( "--- %d %d %d\n" , v[ i ].l , v[ i ].r , v[ i ].val ) ;
        if ( a[ v[ i ].l ] != a[ v[ i ].r ] ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].l ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].r ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
    }
	**/
    if ( n == 200000 ) { printf ( "---- %d\n" , k ) ; }
    for ( i = 0 ; i < 5 ; i ++ ) {
    	if ( v[ ( k - 1 ) ].r + i == ( n - 1 ) ) { continue ; }
    	if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
    	if ( ( v[ ( k - 1 ) ].r - v[ ( k - 1 ) ].l + 1 ) + i > 5 ) { break ; }
        if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
		getdp ( k - 1 , v[ ( k - 1 ) ].r + i ) ;
    }
    printf ( "-1\n" ) ;
}

int main ( ) {
	ios::sync_with_stdio ( false ) ;
	cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std ;

#define MAXN 200007

int n ;
int k ;
int a[ MAXN ] ;

int dp[ MAXN ][ 7 ] ;
int prv[ MAXN ][ 7 ] ;
int ans[ MAXN ] ;

bool fake[ MAXN ][ 7 ] ;

struct tuhla {
	int l , r ;
    int val ;
};

vector < struct tuhla > v ;
int tot ;

void paint_interval ( int lo , int hi , int beg , int en ) {
	//printf ( "%d %d %d %d\n" , l , r , st , br ) ;
   	/**
    if ( n == 200000 ) {
    	if ( lo <= 2485 && hi >= 2485 ) {
			printf ( "%d %d %d %d\n" , lo , hi , beg , en ) ;
        }
    }
	**/
	int i , j , t ;
	i = lo ;
    while ( 1 ) {
    	if ( i > n ) { return ; }
		for ( j = 2 ; j <= 5 ; j ++ ) {
        	int lft = ( ( hi - i + 1 ) - j ) ;
            int pr = en - beg ;
            if ( 2 * pr <= lft && lft <= 5 * pr ) {
            	break ;
            }
        }
        for ( t = 0 ; t < j ; t ++ ) {
        	ans[ i + t ] = beg ;
        }
        beg ++ ;
        i += j ;
    }
}
void paint_range ( int l , int r , int val ) {
	int i ;
    /**
    if ( n == 200000 ) {
    	if ( l <= 2485 && r >= 2485 ) {
			printf ( "%d %d %d\n" , l , r , val ) ;
        }
    }
	**/
    for ( i = l ; i <= r ; i ++ ) {
    	ans[ i ] = val ;
    }
}

bool getdp ( int id , int r ) {
	if ( fake[ id ][ r ] == true ) { return false ; }
	//printf ( "%d %d\n" , id , r ) ;
	if ( id == 0 ) {
    	int pr = v[ id ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
           	//printf ( " YYYY %d %d\n" , pr , ( i - 1 ) ) ;
        	if ( 2 * pr <= ( i - 1 ) && ( i - 1 ) <= 5 * pr ) {
            	if ( i - 1 >= 1 ) { paint_interval ( 1 , i - 1 , 1 , pr ) ; }
                paint_range ( i , r , v[ id ].val ) ;
                if ( k == 1 ) {
					for ( t = r + 1 ; t < n ; t ++ ) {
						if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
						else { ans[ t ] = v[ id ].val ; }
					}
					if ( r != n ) { ans[ n ] = v[ id ].val ; }
					printf ( "%d\n" , ans[ n ] ) ;
					for ( t = 1 ; t <= n ; t ++ ) {
						printf ( "%d" , ans[ t ] ) ;
						if ( t == n ) { printf ( "\n" ) ; }
						else { printf ( " " ) ; }
					}
					exit ( 0 ) ;
                }
                return true ;
            }
        }
    }
    else {
    	int pr = v[ id ].val - v[ id - 1 ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
            //printf ( "~~ %d\n" , i ) ;
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { fake[ id ][ r ] = true ; return false ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
            for ( j = v[ id - 1 ].r ; j <= v[ id - 1 ].l + 4 ; j ++ ) {
            	//printf ( "   ### %d %d\n" , i , j ) ;
            	if ( a[ j ] != 0 && a[ j ] != v[ id - 1 ].val ) { continue ; }
                if ( j >= i ) { break ; }
                int len = ( i - j - 1 ) ;
        		if ( ( 2 * pr <= len && len <= 5 * pr ) && getdp ( id - 1 , j ) == true ) {
            		if ( j + 1 <= i - 1 ) { paint_interval ( j + 1 , i - 1 , v[ id - 1 ].val + 1 , v[ id ].val - 1 ) ; }
                	paint_range ( i , r , v[ id ].val ) ;
                    if ( id == k - 1 ) {
                    	for ( t = r + 1 ; t < n ; t ++ ) {
                        	if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
                            else { ans[ t ] = v[ id ].val ; }
                        }
                        if ( r != n ) { ans[ n ] = v[ id ].val ; }
                        /**
                        int br = 0 ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	if ( ans[ t ] == 0 ) { br ++ ;  }
                        }
						**/
                        //if ( n == 200000 ) { printf ( "TOTAL WRONG --> %d\n" , br ) ; }
                        printf ( "%d\n" , ans[ n ] ) ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	printf ( "%d" , ans[ t ] ) ;
	                        if ( t == n ) { printf ( "\n" ) ; }
                            else { printf ( " " ) ; }
                        }
						exit ( 0 ) ;
                    }
    	            return true ;
	            }
            }
        }
    }
    fake[ id ][ r ] = true ;
    return false ;
}

void input ( ) {
	scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
	int i , j , t ;
    int lst = 0 ;
    int pos = 0 ;
    vector < pair < int , int > > u ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) {
        	if ( lst != 0 && lst > a[ i ] ) { printf ( "-1\n" ) ; return ; }
        	if ( lst != 0 && lst == a[ i ] ) {
            	for ( j = pos ; j <= i ; j ++ ) {
                	a[ j ] = a[ i ] ;
                }
            }
            lst = a[ i ] ;
            pos = i ;
        }
    }
    if ( lst == 0 ) {
		for ( i = 1 ; i <= n ; i ++ ) {
        	if ( i % 2 == 1 ) { ans[ i ] = ( i / 2 + 1 ) ; }
            else { ans[ i ] = ans[ i - 1 ] ; }
        }
        if ( ans[ n ] != ans[ n - 1 ] ) { ans[ n ] = ans[ n - 1 ] ; }
        printf ( "%d\n" , ans[ n ] ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
        	printf ( "%d" , ans[ i ] ) ;
	        if ( i == n ) { printf ( "\n" ) ; }
            else { printf ( " " ) ; }
        }
		return ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) { u.push_back ( make_pair ( a[ i ] , i ) ) ; }
    }
    int br = 1 ;
    int mx = 0 ;
    int sz = u.size ( ) ;
    struct tuhla w ;
	for ( i = 1 ; i < sz ; i ++ ) {
    	if ( u[ i ].first == u[ i - 1 ].first ) { br ++ ; }
        else {
        	if ( mx < br ) { mx = br ; }
            w.r = u[ i - 1 ].second ;
            w.l = u[ i - br ] .second ;
            w.val = a[ u[ i - 1 ].second ] ;
            v.push_back ( w ) ;
            br = 1 ;
        }
    }
	if ( mx < br ) { mx = br ; }

	w.r = u[ i - 1 ].second ;
	w.l = u[ i - br ] .second ;
	w.val = a[ u[ i - 1 ].second ] ;
	v.push_back ( w ) ;
    if ( mx > 5 ) { printf ( "-1\n" ) ; return ; }
	k = v.size ( ) ;
    /**
	for ( i = 0 ; i < k ; i ++ ) {
    	//printf ( "--- %d %d %d\n" , v[ i ].l , v[ i ].r , v[ i ].val ) ;
        if ( a[ v[ i ].l ] != a[ v[ i ].r ] ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].l ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].r ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
    }
    if ( n == 200000 ) { printf ( "---- %d\n" , k ) ; }
	**/

    for ( i = 0 ; i < 5 ; i ++ ) {
    	if ( v[ ( k - 1 ) ].r + i == ( n - 1 ) ) { continue ; }
    	if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
    	if ( ( v[ ( k - 1 ) ].r - v[ ( k - 1 ) ].l + 1 ) + i > 5 ) { break ; }
        if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
		getdp ( k - 1 , v[ ( k - 1 ) ].r + i ) ;
    }
    printf ( "-1\n" ) ;
}

int main ( ) {
	ios::sync_with_stdio ( false ) ;
	cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std ;

#define MAXN 200007

int n ;
int k ;
int a[ MAXN ] ;

int dp[ MAXN ][ 7 ] ;
int prv[ MAXN ][ 7 ] ;
int ans[ MAXN ] ;

struct tuhla {
	int l , r ;
    int val ;
};

vector < struct tuhla > v ;
int tot ;

void paint_interval ( int lo , int hi , int beg , int en ) {
	//printf ( "%d %d %d %d\n" , l , r , st , br ) ;
   	/**
    if ( n == 200000 ) {
    	if ( lo <= 2485 && hi >= 2485 ) {
			printf ( "%d %d %d %d\n" , lo , hi , beg , en ) ;
        }
    }
	**/
	int i , j , t ;
	i = lo ;
    while ( 1 ) {
    	if ( i > n ) { return ; }
		for ( j = 2 ; j <= 5 ; j ++ ) {
        	int lft = ( ( hi - i + 1 ) - j ) ;
            int pr = en - beg ;
            if ( 2 * pr <= lft && lft <= 5 * pr ) {
            	break ;
            }
        }
        for ( t = 0 ; t < j ; t ++ ) {
        	ans[ i + t ] = beg ;
        }
        beg ++ ;
        i += j ;
    }
}
void paint_range ( int l , int r , int val ) {
	int i ;
    /**
    if ( n == 200000 ) {
    	if ( l <= 2485 && r >= 2485 ) {
			printf ( "%d %d %d\n" , l , r , val ) ;
        }
    }
	**/
    for ( i = l ; i <= r ; i ++ ) {
    	ans[ i ] = val ;
    }
}

bool getdp ( int id , int r ) {
	//printf ( "%d %d\n" , id , r ) ;
	if ( id == 0 ) {
    	int pr = v[ id ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
           	//printf ( " YYYY %d %d\n" , pr , ( i - 1 ) ) ;
        	if ( 2 * pr <= ( i - 1 ) && ( i - 1 ) <= 5 * pr ) {
            	if ( i - 1 >= 1 ) { paint_interval ( 1 , i - 1 , 1 , pr ) ; }
                paint_range ( i , r , v[ id ].val ) ;
                if ( k == 1 ) {
					for ( t = r + 1 ; t < n ; t ++ ) {
						if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
						else { ans[ t ] = v[ id ].val ; }
					}
					if ( r != n ) { ans[ n ] = v[ id ].val ; }
					printf ( "%d\n" , ans[ n ] ) ;
					for ( t = 1 ; t <= n ; t ++ ) {
						printf ( "%d" , ans[ t ] ) ;
						if ( t == n ) { printf ( "\n" ) ; }
						else { printf ( " " ) ; }
					}
					exit ( 0 ) ;
                }
                return true ;
            }
        }
    }
    else {
    	int pr = v[ id ].val - v[ id - 1 ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
            //printf ( "~~ %d\n" , i ) ;
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
            for ( j = v[ id - 1 ].r ; j <= v[ id - 1 ].l + 4 ; j ++ ) {
            	//printf ( "   ### %d %d\n" , i , j ) ;
            	if ( a[ j ] != 0 && a[ j ] != v[ id - 1 ].val ) { continue ; }
                if ( j >= i ) { continue ; }
                int len = ( i - j - 1 ) ;
        		if ( ( 2 * pr <= len && len <= 5 * pr ) && getdp ( id - 1 , j ) == true ) {
            		if ( j + 1 <= i - 1 ) { paint_interval ( j + 1 , i - 1 , v[ id - 1 ].val + 1 , v[ id ].val - 1 ) ; }
                	paint_range ( i , r , v[ id ].val ) ;
                    if ( id == k - 1 ) {
                    	for ( t = r + 1 ; t < n ; t ++ ) {
                        	if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
                            else { ans[ t ] = v[ id ].val ; }
                        }
                        if ( r != n ) { ans[ n ] = v[ id ].val ; }
                        /**
                        int br = 0 ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	if ( ans[ t ] == 0 ) { br ++ ;  }
                        }
						**/
                        //if ( n == 200000 ) { printf ( "TOTAL WRONG --> %d\n" , br ) ; }
                        printf ( "%d\n" , ans[ n ] ) ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	printf ( "%d" , ans[ t ] ) ;
	                        if ( t == n ) { printf ( "\n" ) ; }
                            else { printf ( " " ) ; }
                        }
						exit ( 0 ) ;
                    }
    	            return true ;
	            }
            }
        }
    }
    return false ;
}

void input ( ) {
	scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
	int i , j , t ;
    int lst = 0 ;
    int pos = 0 ;
    vector < pair < int , int > > u ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) {
        	if ( lst != 0 && lst > a[ i ] ) { printf ( "-1\n" ) ; return ; }
        	if ( lst != 0 && lst == a[ i ] ) {
            	for ( j = pos ; j <= i ; j ++ ) {
                	a[ j ] = a[ i ] ;
                }
            }
            lst = a[ i ] ;
            pos = i ;
        }
    }
    if ( lst == 0 ) {
		for ( i = 1 ; i <= n ; i ++ ) {
        	if ( i % 2 == 1 ) { ans[ i ] = ( i / 2 + 1 ) ; }
            else { ans[ i ] = ans[ i - 1 ] ; }
        }
        if ( ans[ n ] != ans[ n - 1 ] ) { ans[ n ] = ans[ n - 1 ] ; }
        printf ( "%d\n" , ans[ n ] ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
        	printf ( "%d" , ans[ i ] ) ;
	        if ( i == n ) { printf ( "\n" ) ; }
            else { printf ( " " ) ; }
        }
		return ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) { u.push_back ( make_pair ( a[ i ] , i ) ) ; }
    }
    int br = 1 ;
    int mx = 0 ;
    int sz = u.size ( ) ;
    struct tuhla w ;
	for ( i = 1 ; i < sz ; i ++ ) {
    	if ( u[ i ].first == u[ i - 1 ].first ) { br ++ ; }
        else {
        	if ( mx < br ) { mx = br ; }
            w.r = u[ i - 1 ].second ;
            w.l = u[ i - br ] .second ;
            w.val = a[ u[ i - 1 ].second ] ;
            v.push_back ( w ) ;
            br = 1 ;
        }
    }
	if ( mx < br ) { mx = br ; }

	w.r = u[ i - 1 ].second ;
	w.l = u[ i - br ] .second ;
	w.val = a[ u[ i - 1 ].second ] ;
	v.push_back ( w ) ;
    if ( mx > 5 ) { printf ( "-1\n" ) ; return ; }
	k = v.size ( ) ;
    /**
	for ( i = 0 ; i < k ; i ++ ) {
    	//printf ( "--- %d %d %d\n" , v[ i ].l , v[ i ].r , v[ i ].val ) ;
        if ( a[ v[ i ].l ] != a[ v[ i ].r ] ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].l ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].r ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
    }
	**/
    if ( n == 200000 ) { printf ( "---- %d\n" , k ) ; }
    for ( i = 0 ; i < 5 ; i ++ ) {
    	if ( v[ ( k - 1 ) ].r + i == ( n - 1 ) ) { continue ; }
    	if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
    	if ( ( v[ ( k - 1 ) ].r - v[ ( k - 1 ) ].l + 1 ) + i > 5 ) { break ; }
        if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
		getdp ( k - 1 , v[ ( k - 1 ) ].r + i ) ;
    }
    printf ( "-1\n" ) ;
}

int main ( ) {
	ios::sync_with_stdio ( false ) ;
	cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std ;

#define MAXN 200007

int n ;
int k ;
int a[ MAXN ] ;

int dp[ MAXN ][ 7 ] ;
int prv[ MAXN ][ 7 ] ;
int ans[ MAXN ] ;

struct tuhla {
	int l , r ;
    int val ;
};

vector < struct tuhla > v ;
int tot ;

void paint_interval ( int l , int r , int st , int br ) {
	//printf ( "%d %d %d %d\n" , l , r , st , br ) ;
	int i ;
    for ( i = l ; i <= r ; i ++ ) {
    	if ( st > br ) {
        	ans[ i ] = ans[ i - 1 ] ;
            continue ;
        }
    	if ( ( i - l ) % 2 == 0 ) {
        	ans[ i ] = st ;
            st ++ ;
        }
        else {
        	ans[ i ] = a[ i - 1 ] ;
        }
    }
}
void paint_range ( int l , int r , int val ) {
	int i ;
    for ( i = l ; i <= r ; i ++ ) {
    	ans[ i ] = val ;
    }
}

bool getdp ( int id , int r ) {
	//printf ( "%d %d\n" , id , r ) ;
	if ( id == 0 ) {
    	int pr = v[ id ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
           	//printf ( " YYYY %d %d\n" , pr , ( i - 1 ) ) ;
        	if ( 2 * pr <= ( i - 1 ) && ( i - 1 ) <= 5 * pr ) {
            	paint_interval ( 1 , i - 1 , 1 , pr ) ;
                paint_range ( i , r , v[ id ].val ) ;
                if ( k == 1 ) {
					for ( t = r + 1 ; t < n ; t ++ ) {
						if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
						else { ans[ t ] = v[ id ].val ; }
					}
					if ( r != n ) { ans[ n ] = v[ id ].val ; }
					printf ( "%d\n" , ans[ n ] ) ;
					for ( t = 1 ; t <= n ; t ++ ) {
						printf ( "%d" , ans[ t ] ) ;
						if ( t == n ) { printf ( "\n" ) ; }
						else { printf ( " " ) ; }
					}
					exit ( 0 ) ;
                }
                return true ;
            }
        }
    }
    else {
    	int pr = v[ id ].val - v[ id - 1 ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
            //printf ( "~~ %d\n" , i ) ;
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
            for ( j = v[ id - 1 ].r ; j <= v[ id - 1 ].l + 4 ; j ++ ) {
            	//printf ( "   ### %d %d\n" , i , j ) ;
            	if ( a[ j ] != 0 && a[ j ] != v[ id - 1 ].val ) { continue ; }
                if ( j >= i ) { continue ; }
                int len = ( i - j - 1 ) ;
        		if ( getdp ( id - 1 , j ) == true && ( 2 * pr <= len && len <= 5 * pr ) ) {
            		paint_interval ( j + 1 , i - 1 , v[ id - 1 ].val + 1 , v[ id ].val - 1 ) ;
                	paint_range ( i , r , v[ id ].val ) ;
                    if ( id == k - 1 ) {
                    	for ( t = r + 1 ; t < n ; t ++ ) {
                        	if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
                            else { ans[ t ] = v[ id ].val ; }
                        }
                        if ( r != n ) { ans[ n ] = v[ id ].val ; }
                        printf ( "%d\n" , ans[ n ] ) ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	printf ( "%d" , ans[ t ] ) ;
	                        if ( t == n ) { printf ( "\n" ) ; }
                            else { printf ( " " ) ; }
                        }
						exit ( 0 ) ;
                    }
    	            return true ;
	            }
            }
        }
    }
    return false ;
}

void input ( ) {
	scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
	int i , j , t ;
    int lst = 0 ;
    int pos = 0 ;
    vector < pair < int , int > > u ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) {
        	if ( lst != 0 && lst > a[ i ] ) { printf ( "-1\n" ) ; return ; }
        	if ( lst != 0 && lst == a[ i ] ) {
            	for ( j = pos ; j <= i ; j ++ ) {
                	a[ j ] = a[ i ] ;
                }
            }
            lst = a[ i ] ;
            pos = i ;
        }
    }
    if ( lst == 0 ) {
		for ( i = 1 ; i <= n ; i ++ ) {
        	if ( i % 2 == 1 ) { ans[ i ] = ( i / 2 + 1 ) ; }
            else { ans[ i ] = ans[ i - 1 ] ; }
        }
        if ( ans[ n ] != ans[ n - 1 ] ) { ans[ n ] = ans[ n - 1 ] ; }
        printf ( "%d\n" , ans[ n ] ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
        	printf ( "%d" , ans[ i ] ) ;
	        if ( i == n ) { printf ( "\n" ) ; }
            else { printf ( " " ) ; }
        }
		return ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) { u.push_back ( make_pair ( a[ i ] , i ) ) ; }
    }
    int br = 1 ;
    int mx = 0 ;
    int sz = u.size ( ) ;
    struct tuhla w ;
	for ( i = 1 ; i < sz ; i ++ ) {
    	if ( u[ i ].first == u[ i - 1 ].first ) { br ++ ; }
        else {
        	if ( mx < br ) { mx = br ; }
            w.r = u[ i - 1 ].second ;
            w.l = u[ i - br ] .second ;
            w.val = a[ u[ i - 1 ].second ] ;
            v.push_back ( w ) ;
            br = 1 ;
        }
    }
	if ( mx < br ) { mx = br ; }

	w.r = u[ i - 1 ].second ;
	w.l = u[ i - br ] .second ;
	w.val = a[ u[ i - 1 ].second ] ;
	v.push_back ( w ) ;
    if ( mx > 5 ) { printf ( "-1\n" ) ; return ; }
	k = v.size ( ) ;
    /**
	for ( i = 0 ; i < k ; i ++ ) {
    	printf ( "--- %d %d %d\n" , v[ i ].l , v[ i ].r , v[ i ].val ) ;
    }**/
    for ( i = 0 ; i < 5 ; i ++ ) {
    	if ( v[ ( k - 1 ) ].r + i == ( n - 1 ) ) { continue ; }
    	if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
    	if ( ( v[ ( k - 1 ) ].r - v[ ( k - 1 ) ].l + 1 ) + i > 5 ) { break ; }
        if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
		getdp ( k - 1 , v[ ( k - 1 ) ].r + i ) ;
    }
    printf ( "-1\n" ) ;
}

int main ( ) {
	ios::sync_with_stdio ( false ) ;
	cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std ;

#define MAXN 200007

int n ;
int k ;
int a[ MAXN ] ;

int dp[ MAXN ][ 7 ] ;
int prv[ MAXN ][ 7 ] ;
int ans[ MAXN ] ;

struct tuhla {
	int l , r ;
    int val ;
};

vector < struct tuhla > v ;
int tot ;

void paint_interval ( int lo , int hi , int beg , int en ) {
	//printf ( "%d %d %d %d\n" , l , r , st , br ) ;
    if ( n == 200000 ) {
    	if ( lo <= 2485 && hi >= 2485 ) {
			printf ( "%d %d %d %d\n" , lo , hi , beg , en ) ;
        }
    }
	int i , j , t ;
	i = lo ;
    while ( 1 ) {
    	if ( i > n ) { return ; }
		for ( j = 2 ; j <= 5 ; j ++ ) {
        	int lft = ( ( hi - i + 1 ) - j ) ;
            int pr = en - beg ;
            if ( 2 * pr <= lft && lft <= 5 * pr ) {
            	break ;
            }
        }
        for ( t = 0 ; t < j ; t ++ ) {
        	ans[ i + t ] = beg ;
        }
        beg ++ ;
        i += j ;
    }
}
void paint_range ( int l , int r , int val ) {
	int i ;
    if ( n == 200000 ) {
    	if ( l <= 2485 && r >= 2485 ) {
			printf ( "%d %d %d\n" , l , r , val ) ;
        }
    }
    for ( i = l ; i <= r ; i ++ ) {
    	ans[ i ] = val ;
    }
}

bool getdp ( int id , int r ) {
	//printf ( "%d %d\n" , id , r ) ;
	if ( id == 0 ) {
    	int pr = v[ id ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
           	//printf ( " YYYY %d %d\n" , pr , ( i - 1 ) ) ;
        	if ( 2 * pr <= ( i - 1 ) && ( i - 1 ) <= 5 * pr ) {
            	if ( i - 1 >= 1 ) { paint_interval ( 1 , i - 1 , 1 , pr ) ; }
                paint_range ( i , r , v[ id ].val ) ;
                if ( k == 1 ) {
					for ( t = r + 1 ; t < n ; t ++ ) {
						if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
						else { ans[ t ] = v[ id ].val ; }
					}
					if ( r != n ) { ans[ n ] = v[ id ].val ; }
					printf ( "%d\n" , ans[ n ] ) ;
					for ( t = 1 ; t <= n ; t ++ ) {
						printf ( "%d" , ans[ t ] ) ;
						if ( t == n ) { printf ( "\n" ) ; }
						else { printf ( " " ) ; }
					}
					exit ( 0 ) ;
                }
                return true ;
            }
        }
    }
    else {
    	int pr = v[ id ].val - v[ id - 1 ].val - 1 ;
        int i , j , t ;
        for ( i = v[ id ].l ; i >= r - 4 ; i -- ) {
            //printf ( "~~ %d\n" , i ) ;
        	if ( a[ i ] != 0 && a[ i ] != v[ id ].val ) { continue ; }
            if ( ( r - i + 1 ) < 2 ) { continue ; }
            for ( j = v[ id - 1 ].r ; j <= v[ id - 1 ].l + 4 ; j ++ ) {
            	//printf ( "   ### %d %d\n" , i , j ) ;
            	if ( a[ j ] != 0 && a[ j ] != v[ id - 1 ].val ) { continue ; }
                if ( j >= i ) { continue ; }
                int len = ( i - j - 1 ) ;
        		if ( ( 2 * pr <= len && len <= 5 * pr ) && getdp ( id - 1 , j ) == true ) {
            		if ( j + 1 <= i - 1 ) { paint_interval ( j + 1 , i - 1 , v[ id - 1 ].val + 1 , v[ id ].val - 1 ) ; }
                	paint_range ( i , r , v[ id ].val ) ;
                    if ( id == k - 1 ) {
                    	for ( t = r + 1 ; t < n ; t ++ ) {
                        	if ( ( t - r ) % 2 == 1 ) { v[ id ].val ++ ; ans[ t ] = v[ id ].val ; }
                            else { ans[ t ] = v[ id ].val ; }
                        }
                        if ( r != n ) { ans[ n ] = v[ id ].val ; }
                        int br = 0 ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	if ( ans[ t ] == 0 ) { br ++ ;  }
                        }
                        if ( n == 200000 ) { printf ( "TOTAL WRONG --> %d\n" , br ) ; }
                        printf ( "%d\n" , ans[ n ] ) ;
                        for ( t = 1 ; t <= n ; t ++ ) {
                        	printf ( "%d" , ans[ t ] ) ;
	                        if ( t == n ) { printf ( "\n" ) ; }
                            else { printf ( " " ) ; }
                        }
						exit ( 0 ) ;
                    }
    	            return true ;
	            }
            }
        }
    }
    return false ;
}

void input ( ) {
	scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
	int i , j , t ;
    int lst = 0 ;
    int pos = 0 ;
    vector < pair < int , int > > u ;
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) {
        	if ( lst != 0 && lst > a[ i ] ) { printf ( "-1\n" ) ; return ; }
        	if ( lst != 0 && lst == a[ i ] ) {
            	for ( j = pos ; j <= i ; j ++ ) {
                	a[ j ] = a[ i ] ;
                }
            }
            lst = a[ i ] ;
            pos = i ;
        }
    }
    if ( lst == 0 ) {
		for ( i = 1 ; i <= n ; i ++ ) {
        	if ( i % 2 == 1 ) { ans[ i ] = ( i / 2 + 1 ) ; }
            else { ans[ i ] = ans[ i - 1 ] ; }
        }
        if ( ans[ n ] != ans[ n - 1 ] ) { ans[ n ] = ans[ n - 1 ] ; }
        printf ( "%d\n" , ans[ n ] ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
        	printf ( "%d" , ans[ i ] ) ;
	        if ( i == n ) { printf ( "\n" ) ; }
            else { printf ( " " ) ; }
        }
		return ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
    	if ( a[ i ] != 0 ) { u.push_back ( make_pair ( a[ i ] , i ) ) ; }
    }
    int br = 1 ;
    int mx = 0 ;
    int sz = u.size ( ) ;
    struct tuhla w ;
	for ( i = 1 ; i < sz ; i ++ ) {
    	if ( u[ i ].first == u[ i - 1 ].first ) { br ++ ; }
        else {
        	if ( mx < br ) { mx = br ; }
            w.r = u[ i - 1 ].second ;
            w.l = u[ i - br ] .second ;
            w.val = a[ u[ i - 1 ].second ] ;
            v.push_back ( w ) ;
            br = 1 ;
        }
    }
	if ( mx < br ) { mx = br ; }

	w.r = u[ i - 1 ].second ;
	w.l = u[ i - br ] .second ;
	w.val = a[ u[ i - 1 ].second ] ;
	v.push_back ( w ) ;
    if ( mx > 5 ) { printf ( "-1\n" ) ; return ; }
	k = v.size ( ) ;
    /**
	for ( i = 0 ; i < k ; i ++ ) {
    	//printf ( "--- %d %d %d\n" , v[ i ].l , v[ i ].r , v[ i ].val ) ;
        if ( a[ v[ i ].l ] != a[ v[ i ].r ] ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].l ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
        if ( a[ v[ i ].r ] != v[ i ].val ) { printf ( "WTF??\n" ) ; }
    }
	**/
    if ( n == 200000 ) { printf ( "---- %d\n" , k ) ; }
    for ( i = 0 ; i < 5 ; i ++ ) {
    	if ( v[ ( k - 1 ) ].r + i == ( n - 1 ) ) { continue ; }
    	if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
    	if ( ( v[ ( k - 1 ) ].r - v[ ( k - 1 ) ].l + 1 ) + i > 5 ) { break ; }
        if ( v[ ( k - 1 ) ].r + i > n ) { continue ; }
		getdp ( k - 1 , v[ ( k - 1 ) ].r + i ) ;
    }
    printf ( "-1\n" ) ;
}

int main ( ) {
	ios::sync_with_stdio ( false ) ;
	cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}