#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>

using namespace std;

//#define GEN_LOCAL_TEST
//#define USE_LOCAL_TEST

#ifdef GEN_LOCAL_TEST
void genTest() {
    ofstream ofs("test.txt", ifstream::out);
    int n = 200000;
    ofs << n << endl;
    for (int i = 0; i < n - 100000; ++i)
        ofs << 1 << " ";
    for (int i = 0; i < 100000; ++i)
        ofs << 0 << " ";
    ofs << endl;
    ofs.close();
}
#endif

int main(int argc, char* argv[])
{
#ifdef GEN_LOCAL_TEST
    genTest();
#endif

    int n;
#ifdef USE_LOCAL_TEST
    ifstream ifs("test.txt", ifstream::in);
    ifs >> n;
#else
    cin >> n;
#endif

    long long int val;
    vector<long long int> dt;
    for (int i = 0; i < n; ++i) {
#ifdef USE_LOCAL_TEST
        ifs >> val;
#else
        cin >> val;
#endif
        dt.push_back(val);
    }

    long long int qt = 0;
    for (int i = 1; i < n; ++i) {
        if (dt[i] == 0) ++qt;
    }
    vector<long long int> qt1;
    for (int i = 0; i < n - 1; ++i) {
        qt1.push_back(qt);
        if (dt[i + 1] == 0) --qt;
    }
    qt1.push_back(0);

    qt = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (dt[i] == 1) ++qt;
    }
    vector<long long int> qt2(n, 0);
    for (int i = n - 1; i > 0; --i) {
        qt2[i] = qt;
        if (dt[i - 1] == 1) --qt;
    }

    long long int res1 = 0;
    long long int add = 0;
    for (int i = 0; i < n; ++i) {
        if (dt[i] != 1) continue;
        res1 += qt1[i];
        ++add;
        if (add >= qt2[n - 1])
            break;
    }
    long long int res2 = 0;
    add = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (dt[i] != 0) continue;
        res2 += qt2[i];
        ++add;
        if (add >= qt1[0])
            break;
    }
    cout << min(res1, res2);
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int N,q,t,j;
int main(){
	cin>>N;
	vector <int> a;
	for(int i = 1;i <= N; ++i){
		cin>>t;
		if(a.empty() && !t)
			continue;
		a.push_back(t);
	}
	if(a.empty()){
		cout<<0<<endl;return 0;
	}
	a.push_back(1);
	N=a.size()-2;
	vector <int> c(N+2);
	for(int i = N-1; i >= 0; --i)
		if(a[i+1]){
			c[i]=c[i+1];
		}
		else{
			c[i]=c[i+1]+1;
		}
	for(size_t i = 0;i < N; ++i)
		if(a[i])
			q+=c[i];
	cout<<q<<endl;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int N,q,t,j;
int main(){
	cin>>N;
	vector <int> a;
	for(int i = 1;i <= N; ++i){
		cin>>t;
		if(a.empty() && !t)
			continue;
		a.push_back(t);
	}
	a.push_back(1);
	N=a.size()-2;
	vector <int> c(N+2);
	for(int i = N-1; i >= 0; --i)
		if(a[i+1]){
			c[i]=c[i+1];
		}
		else{
			c[i]=c[i+1]+1;
		}
	for(size_t i = 0;i < N; ++i)
		if(a[i])
			q+=c[i];
	cout<<q<<endl;
	return 0;
}


#include <iostream>
using namespace std;
long long q;int a,c,n,i;
int main()
{
	cin>>n;
	for(i=1;i<=n;++i){
		cin>>a;
		if(!a)
			q+=c;
		else
			c++;
	}
	cout<<q<<endl;
	return 0;
}


#include <iostream>
using namespace std;
long long n,a,c,i,q;
int main()
{
	cin>>n;
	for(i=1;i<=n;++i){
		cin>>a;
		if(!a)
			q+=c;
		else
			c++;
	}
	cout<<q<<endl;
	return 0;
}


#include <iostream>
using namespace std;
int a[200002],N,b[200002],q;
int main(){
	cin>>N;
	for(int i = 1;i <= N; ++i){
		cin>>a[i];
		if(a[i]==1)
			b[i]=b[i-1]+1;
		else
			b[i]=b[i-1];
		if(a[i]==0)
			q+=b[i];
	}
	cout<<q<<endl;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
long long N,q,t,j;
int main(){
	cin>>N;
	vector <int> a;
	for(int i = 1;i <= N; ++i){
		cin>>t;
		if(a.empty() && !t)
			continue;
		a.push_back(t);
	}
	if(a.empty()){
		cout<<0<<endl;return 0;
	}
	a.push_back(1);
	N=a.size()-2;
	vector <int> c(N+2);
	for(int i = N-1; i >= 0; --i)
		if(a[i+1])
			c[i]=c[i+1];
		else
			c[i]=c[i+1]+1;
	for(size_t i = 0;i < N; ++i)
		if(a[i])
			q+=c[i];
	cout<<q<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <queue>
#include <numeric>
#include <list>
#pragma warning (default : 4996)
using namespace std;

#define eps 1e-8
#define LL long long
#define ULL unsigned long long
#define mod 1000000007
#define MP make_pair
#define mxn 200005
int vis[mxn], a[mxn],c0[mxn],c1[mxn];
int i, n;
int cnt0, cnt1;
int ans = 0;
int main()
{
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d",&a[i]);
		if (a[i] == 0) {
			cnt0++;
			c0[cnt0] = cnt1;
		}
		if (a[i] == 1) {
			cnt1++;
			c1[cnt1] = cnt0;

		}
	}
	if (cnt0 < cnt1) {
		for (i = cnt0; i >= 1; i--) {
			ans += c0[i];
		}
	}
	else {
		for (i = 1; i <= cnt1; i++) {
			ans += cnt0 - c1[i];
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <queue>
#include <numeric>
#include <list>
#pragma warning (default : 4996)
using namespace std;

#define eps 1e-8
#define LL long long
#define ULL unsigned long long
#define mod 1000000007
#define MP make_pair
#define mxn 200005
int vis[mxn], a[mxn],c0[mxn],c1[mxn];
int i, n;
int cnt0, cnt1;
LL ans = 0;
int main()
{
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d",&a[i]);
		if (a[i] == 0) {
			cnt0++;
			c0[cnt0] = cnt1;
		}
		if (a[i] == 1) {
			cnt1++;
			c1[cnt1] = cnt0;

		}
	}
	if (cnt0 < cnt1) {
		for (i = cnt0; i >= 1; i--) {
			ans += c0[i] + 0ll;
		}
	}
	else {
		for (i = 1; i <= cnt1; i++) {
			ans += (cnt0 - c1[i]) + 0ll;
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include <cstdio>

#define MAXN 200005

int N, A[MAXN], C[MAXN][2], T[2];

int main(void){
    scanf("%d", &N);
    for (int i = 1; i <= N; i ++) {
        scanf("%d", &A[i]);
        for (int j = 0; j < 2; j ++) C[i][j] = C[i-1][j];
        C[i][A[i]] ++;
        T[A[i]] ++;
    }
    long long P = 0;
    for (int i = 1; i <= N; i ++) {
        if (A[i] == 0) {
            P += (long long)(C[i-1][1]);
        }
    }
    printf("%I64d\n", P);
    return 0;
}


//          be name khoda

#include <iostream>

using namespace std;

typedef long long ll;
const ll maxN = 202000;
const ll INF = maxN * maxN;

ll z[maxN], o[maxN], a[maxN];

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        if(a[i])
            o[i] = o[i - 1] + 1;
        else
            o[i] = o[i - 1];
    for(int i = n; i >0; i--)
        if(a[i] == 0)
            z[i] = z[i + 1] + 1;
        else
            z[i] = z[i + 1];
    ll anso = 0, ansz = 0;
    for(int i = 1; i <= n; i++)
        if(a[i] == 0)
            ansz += o[i - 1];
        else
            anso += z[i + 1];
    cout << min(ansz, anso) << endl;        // Ooops!!:D:D ansz = anso :P
    cin >> n;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (l-x);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0,r = 0,l = 0;
	bool k = false;
	for(int y = 0;y < n;y++)
	{
		if(cow[y] == 0)
		{
			r++;
		}
	}
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
				if(k == true)
				{
				    r = r - (x - l - 1);
				}
				p += r;
				l = x;
				k = true;
		}
	}
	cout << p;
	//system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true && p-l > 0)
			{
				p += (p - l);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	//system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (p - l);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	long long p = 0,r = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (r - (x - l - 1));
				r = r - (x - l - 1);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						r++;
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (x-l);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (p - l);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			for(int y = x;y < n;y++)
			{
				if(cow[y] == 0)
				{
					p++;
				}
			}
		}
	}
	cout << p;
	system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0,r = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (r - (x - l - 1));
				r = r - (x - l - 1);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						r++;
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	//system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	long long p = 0,r = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (r - (x - l - 1));
				r = r - (x - l - 1);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						r++;
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	//system("Pause");
	return 0;
}


#include <iostream>
using namespace std;
int cow[200009];
int main()
{
	bool k = false;
	int l = 0;
	int n;
	cin >> n;
	for(int t = 0;t < n;t++)
	{
		cin >> cow[t];
	}
	int p = 0;
	for(int x = 0;x < n;x++)
	{
		if(cow[x] == 1)
		{
			if(k == true)
			{
				p += (p - x + l + 1);
			}
			else
			{
				for(int y = x;y < n;y++)
				{
					if(cow[y] == 0)
					{
						p++;
					}
				}
			}
			l = x;
			k = true;
		}
	}
	cout << p;
	//system("Pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200000;

typedef long long ll;

int n, a[N], s[N];

int main(void) {
    ll ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (i) s[i] = s[i - 1] + a[i];
        if (a[i] == 0 && i) ans += (ll)s[i - 1];
    }
    cout << ans << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200000;

typedef long long ll;

int n, a[N], s[N];

int main(void) {
    ll ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (i) s[i] = s[i - 1] + a[i];
        else s[i] = a[i];
        if (a[i] == 0 && i) ans += (ll)s[i - 1];
    }
    cout << ans << endl;
    return 0;
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MEM(x,y) (memset((x),(y),sizeof(x)))
const int N = 200000;

int main()
{
	//freopen("input.txt", "r", stdin);
	LL cnt = 0;
	int n;
	cin >> n;
	int x;
	LL ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		if (x == 1) cnt++;
		if (x == 0)ans += cnt;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    int a;
    int ed = 0;
    long long ans = 0;

    cin >> n;

    for(int i = 0; i < n; ++i)
    {
        cin >> a;
        if(a)
        {
            ++ed;
        }
        else
        {
            ans += ed;
        }
    }

    cout << ans << endl;

    return 0;
}


#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <functional>
using namespace std;
#define F(i,m) for(int i=0;i<m;++i)
#define pb push_back
#define mp make_pair

typedef vector<int> vint;
typedef long long ll;

bool ordenasc(int i, int j){ return i > j; }

int main(){
	int n;
	cin >> n;
	ll res;
	ll conta =res= 0;
	int aux;
	F(i, n){
		cin >> aux;
		if (aux == 1)
			conta++;
		else
			res += conta;
	}
	cout << res;
	return 0;

}


#include <iostream>
using namespace std;
long long n,i,j,k,a[222222],b[222222],l=0,r=0,ans=0;
int main()
{
	cin>>n;
	for (i=1; i<=n; i++)
	{
		cin>>a[i];
		if (a[i]==0) l++;
	}
	for (i=1; i<=n; i++)
	{
		if (a[i]==1) ans+=l;
		else l--;
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>

using namespace std;

const int N = 200010;

int n;
int a[N], l[N], r[N];
long long ans1 = 0, ans2 = 0;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    r[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        r[i] = r[i - 1];
        if (a[i] == 1)
            r[i]++;
    }
    l[n + 1] = 0;
    for (int i = n; i > 0; --i)
    {
        l[i] = l[i + 1];
        if (a[i] == 0)
            l[i]++;
    }
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] == 1)
            ans1 += l[i];
    }
    for (int i = n; i > 0; --i)
    {
        if (a[i] == 0)
            ans2 += r[i];
    }
    printf("%I64d", min(ans1, ans2));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;

    cin>>n>>m;
     vector <vector<char>> v(n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(i%2==0)
            {
                v[i].push_back('#');
            }
            else if(j==m-1)
            {
                v[i].push_back('#');

            }
            else
            {
                v[i].push_back('.');
            }
        }
    }

      for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cout<<v[i][j];
        }
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;

    cin>>n>>m;
     vector <vector<char>> v(n);
     int fl=1,ch=0;
    for(i=0;i<n;i++)
    {   ch=0;
        for(j=0;j<m;j++)
        {
            if(i%2==0)
            {
                v[i].push_back('*');
            }
            else if(j==m-1&&fl==1&&ch==0)
            {
                v[i].push_back('#');
                fl=0;

            }
             else if(j==0&&fl==0)
            {
                v[i].push_back('#');
                fl=1;ch=1;

            }
            else
            {
                v[i].push_back('.');
            }
        }
    }

      for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cout<<v[i][j];
        }
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;

    cin>>n>>m;
     vector <vector<char>> v(n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(i%2==0)
            {
                v[i].push_back('*');
            }
            else if(j==m-1)
            {
                v[i].push_back('*');

            }
            else
            {
                v[i].push_back('.');
            }
        }
    }

      for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cout<<v[i][j];
        }
        cout<<"\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
    int c = m-1;
   char snake[n][m];
   for(int r = 0; r < n ; r ++)
   {
       if(r % 2 == 0)
       {
           for(int c = 0 ; c < m ; c++)
            {
                snake[r][c] = '#';
            }
       }
        else
        {
            snake[r][c] = '#';
            if(c==(m-1))
                c= 0;
            else
                c = m-1;

        }
   }

   for(int r = 0 ; r < n ; r++ )
   {
       for(int c = 0 ; c <m ; c++)
       {
           if(snake[r][c] != '#')
             snake[r][c] = '.';
       }
   }
   for(int r = 0; r < n ; r++ )
   {
       for(int c = 0 ; c < m ; c++)
       {
           cout<<snake[r][c];
       }
       cout<<"\n";
   }

 return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
    int c = m-1;
   char snake[n][m];
   for(int r = 0; r < n ; r ++)
   {
       if(r % 2 == 0)
       {
           for(int c = 0 ; c < m ; c++)
            {
                snake[r][c] = '#';
            }
       }
        else
        {
             for(int c = 0 ; c <m ; c++)
       {

             snake[r][c] = '.';
       }
            snake[r][c] = '#';
            if(c==(m-1))
                c= 0;
            else
                c = m-1;

        }
   }

   for(int r = 0; r < n ; r++ )
   {
       for(int c = 0 ; c < m ; c++)
       {
           cout<<snake[r][c];
       }
       cout<<"\n";
   }

 return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
    int c = m;
   char snake[n+2][m+2];
   for(int r = 1; r <= n ; r ++)
   {
       if(r % 2 != 0)
       {
           for(int c = 0 ; c <= m ; c++)
            {
                snake[r][c] = '#';
            }
       }
        else
        {
            snake[r][c] = '#';
            if(c==(m))
                c= 1;
            else
                c = m;

        }
   }

   for(int r = 1 ; r <= n ; r++ )
   {
       for(int c = 1 ; c <= m ; c++)
       {
           if(snake[r][c] == '#') continue;
           else
            snake[r][c] = '.';
       }
   }
   for(int r = 1; r <= n ; r++ )
   {
       for(int c = 1 ; c <= m ; c++)
       {
           cout<<snake[r][c];
       }
       cout<<"\n";
   }

 return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
    int c = m-1;
   char snake[n][m];
   for(int r = 0; r < n ; r ++)
   {
       if(r % 2 == 0)
       {
           for(int c = 0 ; c < m ; c++)
            {
                snake[r][c] = '#';
            }
       }
        else
        {
             for(int c = 0 ; c <m ; c++)
       {
           if(snake[r][c] != '#')
             snake[r][c] = '.';
       }
            snake[r][c] = '#';
            if(c==(m-1))
                c= 0;
            else
                c = m-1;

        }
   }

   for(int r = 0; r < n ; r++ )
   {
       for(int c = 0 ; c < m ; c++)
       {
           cout<<snake[r][c];
       }
       cout<<"\n";
   }

 return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
    int c = m-1;
   char snake[n][m];
   for(int r = 0; r < n ; r ++)
   {
       if(r % 2 == 0)
       {
           for(int c = 0 ; c < m ; c++)
            {
                snake[r][c] = '#';
            }
       }
        else
        {
            snake[r][c] = '#';
            if(c==(m-1))
                c= 0;
            else
                c = m-1;

        }
   }

   for(int r = 0 ; r < n ; r++ )
   {
       for(int c = 0 ; c <m ; c++)
       {
           if(snake[r][c] == '#') continue;
           else
            snake[r][c] = '.';
       }
   }
   for(int r = 0; r < n ; r++ )
   {
       for(int c = 0 ; c < m ; c++)
       {
           cout<<snake[r][c];
       }
       cout<<"\n";
   }

 return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
    int c = m-1;
   char snake[n][m];
   for(int r = 0 ; r < n ; r ++)
   {
       if(r % 2 == 0)
       {
           for(int c = 0 ; c < m ; c++)
            {
                snake[r][c] = '#';
            }
       }
        else
        {
            snake[r][c] = '#';
            if(c==(m-1))
                c= 0;
            else
                c = m-1;

        }
   }

   for(int r = 0 ; r < n ; r++ )
   {
       for(int c = 0 ; c < m ; c++)
       {
           if(snake[r][c] == '#') continue;
           else
            snake[r][c] = '.';
       }
   }
   for(int r = 0 ; r < n ; r++ )
   {
       for(int c = 0 ; c < m ; c++)
       {
           cout<<snake[r][c];
       }
       cout<<"\n";
   }

 return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,alt=0,q;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m-1;j++)
        {
            if(i%2)
            {
                cout<<"#"
            }
            else
            {
                q=i/2;
                if(alt){
                    q-=1;
                }
                if(q%2)
                {
                    cout<<".";
                }
                else
                {
                    cout<<"#";
                    alt=1;
                }
            }
        }
        if(q%2)
        {
            if(!alt)
            {
                cout<<"#"<<endl;
            }
            else
            {
                cout<<"."<<endl;
                alt=0;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,alt=0,q;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m-1;j++)
        {
            if(i%2)
            {
                cout<<"#";
            }
            else
            {
                q=i/2;
                if(alt){
                    q-=1;
                }
                if(q%2)
                {
                    cout<<".";
                }
                else
                {
                    cout<<"#";
                    alt=1;
                }
            }
        }
        if(q%2)
        {
            if(!alt)
            {
                cout<<"#"<<endl;
            }
            else
            {
                cout<<"."<<endl;
                alt=0;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,alt=0,q;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m-1;j++)
        {
            if(i%2)
            {
                cout<<"#";
            }
            else
            {
                q=i/2;
                if(alt){
                    q-=1;
                }
                if(q%2)
                {
                    cout<<".";
                }
                else
                {
                    cout<<"#";
                    alt=1;
                }
            }
        }
        if(q%2 && i%2==0)
        {
            if(!alt)
            {
                cout<<"#"<<endl;
            }
            else
            {
                cout<<"."<<endl;
                alt=0;
            }
        }
        else
        {
            cout<<"#"<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,alt=0,q;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m-1;j++)
        {
            if(i%2)
            {
                cout<<"#";
            }
            else
            {
                q=i/2;
                if(alt){
                    q-=1;
                }
                if(q%2)
                {
                    cout<<".";
                }
                else
                {
                    cout<<"#";
                    alt=1;
                }
            }
        }
        if(q%2 && i%2==0)
        {
            if(!alt)
            {
                cout<<"#"<<endl;
            }
            else
            {
                cout<<"."<<endl;
                alt=0;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long m , n , i , j;
    cin >> n >> m;
    for (i = 1 ; i <= n ; i ++)
    {
        if (i % 2 != 0)
        {
            for (j = 1 ; j <= m ; j ++)
            {
                cout << '#';
            }
            cout << endl;
        }
        else
        {
            for (j = 1 ; j <= m - 1 ; j ++)
            {
                cout << '.';
            }
            cout << " #";
            cout << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long m , n , i , j;
    bool bl;
    cin >> n >> m;
    bl = true;
    for (i = 1 ; i <= n ; i ++)
    {
        if (i % 2 != 0)
        {
            for (j = 1 ; j <= m ; j ++)
            {
                cout << '#';
            }
            if (i != n)
            {
                cout << endl;
            }
        }
        else
        {
            if (bl == true)
            {
                for (j = 1 ; j <= m - 1 ; j ++)
                {
                    cout << '.';
                }
                cout << '#' << endl;
                bl = false;
            }
            else
            {
                cout << '#';
                for (j = 1 ; j <= m - 1 ; j ++)
                {
                    cout << '.';
                }
                cout << endl;
                bl = true;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long m , n , i , j;
    cin >> n >> m;
    for (i = 1 ; i <= n ; i ++)
    {
        if (i % 2 != 0)
        {
            for (j = 1 ; j <= m ; j ++)
            {
                cout << '#';
            }
            if (i != n)
            {
                cout << endl;
            }
        }
        else
        {
            for (j = 1 ; j <= m - 1 ; j ++)
            {
                cout << '.';
            }
            cout << ' ';
            cout << '#' << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long m , n , i , j;
    cin >> n >> m;
    for (i = 1 ; i <= n ; i ++)
    {
        if (i % 2 != 0)
        {
            for (j = 1 ; j <= m ; j ++)
            {
                cout << '#';
            }
            if (i != n)
            {
                cout << endl;
            }
        }
        else
        {
            for (j = 1 ; j <= m - 1 ; j ++)
            {
                cout << '.';
            }
            cout << '#' << endl;
        }
    }
    return 0;
}


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

int main()
{
	int m,n;
	cin>>m>>n;

	char arr[m][n];
	int f=1;

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			arr[i][j]='.';
		}
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i%2==0)
			{
				if(f==1)
				{
					arr[i-1][m-1] ='#';
				}
				else
				{
					arr[i-1][0]='#';
				}

			}
			else
			{
				arr[i-1][j]='#';
			}
		}

		if(f==1 && i%2==0) f=0;
		else if( f==0 && i%2==0) f=1;

	}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cout<<arr[i][j];
		}
		cout<<endl;
	}

	return 0;
}


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

int main()
{
	int m,n;
	cin>>m>>n;

	char arr[m][n];
	int f=1;

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			arr[i][j]='.';
		}
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i%2==0)
			{
				if(f==1)
				{
					arr[i-1][m-1] ='#';
				}
				else
				{
					arr[i-1][0]='#';
				}

			}
			else
			{
				arr[i-1][j]='#';
			}
		}

		if(f==1 && i%2==0) f=0;
		else if( f==0 && i%2==0) f=1;

	}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cout<<arr[i][j]<<" ";
		}
		cout<<endl;
	}

	return 0;
}


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

int main()
{
	int m,n;
	cin>>n>>m;

	char arr[m][n];
	int f=1;

	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			arr[i][j]='.';
		}
	}

	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i%2==0)
			{
				if(f==1)
				{
					arr[i-1][n-1] ='#';
				}
				else
				{
					arr[i-1][0]='#';
				}

			}
			else
			{
				arr[i-1][j]='#';
			}
		}

		if(f==1 && i%2==0) f=0;
		else if( f==0 && i%2==0) f=1;

	}

	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<arr[i][j];
		}
		cout<<endl;
	}

	return 0;
}


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

int main()
{
	int m,n;
	cin>>m>>n;

	char arr[m][n];
	int f=1;

	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			arr[i][j]='.';
		}
	}

	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i%2==0)
			{
				if(f==1)
				{
					arr[i-1][n-1] ='#';
				}
				else
				{
					arr[i-1][0]='#';
				}

			}
			else
			{
				arr[i-1][j]='#';
			}
		}

		if(f==1 && i%2==0) f=0;
		else if( f==0 && i%2==0) f=1;

	}

	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<arr[i][j];
		}
		cout<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
const int maxn = 6000;
using namespace std;
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0)
			for (int j = 0; j < m; j++)
				printf("%c", '#');
		else if (i % 4 == 1)
		{
			for (int j = 0; j < m - 1; j++)
				printf("%c", '.');
			printf("%c", '#');
		}
		else
		{
			printf("%c", '#');
			for (int j = 0; j < m - 1; j++)
				printf("%c", '.');
		}
		puts("");

	}
}


// fyt
#include<bits/stdc++.h>
#define int long long
#define double long double
#define endl '\n'
using namespace std;

signed main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int n,m;
	cin >> n >> m;
	string s;
	string l;
	string r;
	for (int i=0; i<m; i++){
		s.push_back('#');
	}
	for (int i=0; i<m-1; i++){
		l.push_back('.');
		r.push_back('.');
	}
	r.push_back('#');
	l.push_back('#');
	reverse(l.begin(),l.end());

	bool f = 1;
	for (int i=0; i<n; i++){
		if(i%2 == 0) {
			cout << s << endl;
		}
		else {
			if (f) {
				cout << r << endl;
			}
			else {
				cout << l << endl;
			}
			f = !f;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        if (i & 1)
        {
            for (int j = 1; j <= m; j++)
                putchar('#');
            putchar('\n');
        }
        else
        {
            if ((i >> 1) & 1)
            {
                for (int j = 1; j < m; j++)
                    putchar('.');
                printf("#\n");
            }
            else
            {
                printf("#");
                for (int j = 1; j < m; j++)
                    putchar('.');
                putchar('\n');
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <list>
#include <cstring>
#include <algorithm>
using namespace std;

char g[101][101];

int main(){
	memset(g,'.',sizeof(g));
	int n,m;
	cin>>n>>m;
	for (int i=1;i<=n;i+=2){
		for (int j=1;j<=m;j++){
			g[i][j]='#';
		}
	}
	for (int i=2;i<=n;i+=2){
		int a=i/2;
		if (a%2) g[i][m]='#';
		else g[i][1]='#';
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			printf("%c",g[i][j]);
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,m;
   cin>>n>>m;
   int i,j;
   for(i=0;i<n;i++){
      switch(i%4){
      case 0:case 2:
for(j=0;j<m;j++)cout<<'*';break;
      case 1:
for(j=0;j<m-1;j++)cout<<'.';
cout<<'*';break;
      case 2:
cout<<'*';
for(j=1;j<m;j++)cout<<'.';
      break;

      }
cout<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,m;
   cin>>n>>m;
   int i;
   for(i=0;i<n;i++){
      switch(i%4){
      case 0:case 2:
for(j=0;j<m;j++)cout<<'*';break;
      case 1:
for(j=0;j<m-1;j++)cout<<'.';
cout<<'*';break;
      case 2:
cout<<'*';
for(j=1;j<m;j++)cout<<'.';
      break;

      }
cout<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,m;
   cin>>n>>m;
   int i,j;
   for(i=0;i<n;i++){
      switch(i%4){
      case 0:case 2:
        for(j=0;j<m;j++)cout<<'*';break;
      case 1:
        for(j=0;j<m-1;j++)cout<<'.';
        cout<<'*';break;
      case 3:
cout<<'*';
for(j=1;j<m;j++)cout<<'.';
      break;

      }
cout<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,m;
   cin>>n>>m;
   int i,j;
   for(i=0;i<n;i++){
      switch(i%4){
      case 0:case 2:
        for(j=0;j<m;j++)cout<<'#';break;
      case 1:
        for(j=0;j<m-1;j++)cout<<'.';
        cout<<'#';break;
      case 3:
cout<<'#';
for(j=1;j<m;j++)cout<<'.';
      break;

      }
cout<<endl;
   }

}


#include<iostream>
using namespace std;
char s[51][51];
int main()
{
	int n,m,flag=1;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		{
			for(int j=0;j<m;j++)cout<<"#";
			cout<<endl;
		}
		else if(flag)
		{
			for(int j=0;j<m-1;j++)cout<<".";
			cout<<"#"<<endl;
			flag=!flag;
		}
		else
		{
			cout<<"#";
			for(int j=0;j<m-1;j++)cout<<".";
			cout<<endl;
			flag=!flag;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    for(i=1; i<=n; i++)
    {
        if(i%2==1)
        {
            for(j=1; j<=m; j++)
            {
                cout<<'#';
            }
            cout<<"\n";
        }
        else if(i%4==0)
        {
            for(j=1; j<m; j++)
            {
                cout<<'.';
            }
            cout<<'#'; //Print # into m-th index
            cout<<"\n";
        }
        else
        {
            cout<<'#'; //Print # into 1-th index
            for(j=2; j<m; j++)
            {
                cout<<'.';
            }
            cout<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    for(i=0; i<n; i++)
    {
        if(i%2==0)
        {
            for(j=1; j<=m; j++)
            {
                cout<<'#';
            }
            cout<<"\n";
        }
        else if(i%4==1)
        {
            for(j=1; j<m; j++)
            {
                cout<<'.';
            }
            cout<<'#'; //Print # into m-th index
            cout<<"\n";
        }
        else
        {
            cout<<'#'; //Print # into 1-th index
            for(j=1; j<m; j++)
            {
                cout<<'.';
            }
            cout<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    for(i=0; i<n; i++)
    {
        if(i%2==0)
        {
            for(j=1; j<=m; j++)
            {
                cout<<'#';
            }
            cout<<"\n";
        }
        else if(i%4==1)
        {
            for(j=1; j<m; j++)
            {
                cout<<'.';
            }
            cout<<'#'; //Print # into m-th index
            cout<<"\n";
        }
        else if(i%2==1)
        {
            cout<<'#'; //Print # into 1-th index
            for(j=1; j<m; j++)
            {
                cout<<'.';
            }
            cout<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i, j, n, m;
    cin>>n>>m;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            if(i%2==1)
            {
                cout<<"#";
            }
            else
            {
                if(j==m)
                {
                    cout<<"#";
                }
                else
                {
                    cout<<".";
                }
            }
        }
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, i, j;
	cin >> n >>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(i%2==1 || i%4==0 && j==1 || i%4==2 && j==m)
			 cout <<"#";
			else
			cout<< ".";
		}
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n,m;
    string str;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            if (i%2==1 || (i%4==0 && j==1) || (i%4==2 && j==m))
            str="#";
            else
            str=".";
        }
        puts("");
        cout<<str;
    }

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, i, j;
	cin >> n >>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(i%2==1 || i%4==0 && j==1 || i%4==2 && j==m)
			 cout <<"#";
			else
			cout<< ".";
		}
		puts("");
		/* puts(), here means that after each i executes then it hits enter
		and print in new line*/
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            if (i%2==1 || (i%4==0 && j==1) || (i%4==2 && j==m))
            cout<<"#";
            else
            cout<<".";
        }
        puts("");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, i, j;
	cin >> n >>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(i%2==1 || (i%4==0 && j==1) || (i%4==2 && j==m))
			 cout <<"#";
			else
			cout<< ".";
		}
		puts("");
		/* puts(), here means that after each i executes then it hits enter
		and print in new line*/
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, i, j;
	cin >> n >>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(i%2==1 || i%4==0 && j==1 || i%4==2 && j==m)
			 cout <<"#";
			else
			cout<< ".";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define st struct
#define show(a) for(i=0;i<a.size();i++) cout<<a[i]<<" ";
#define p printf
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long int>
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);
#define long_zero 0ll
#define long_one 1ll

using namespace std;

int main() {
    fast_io()
    int n,m,i,j;
    cin>>n>>m;
    string str;
    for(i=1;i<=n;i++){
        if(i%2){
            str="";
            for(j=1;j<=m;j++)
                str+='#';
        }
        else if((i%2==0)&&(i%4==0)){
            str="#";
            for(j=2;j<=m;j++)
                str+='.';
        }
        else{
            str="";
            for(j=2;j<=m;j++)
                str+='.';
            str+='#';
        }
        cout<<str<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n,m;
    string str;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            if (i%2==1 || (i%4==0 && j==1) || (i%4==2 && j==m))
            str="#";
            else
            str=".";
        }
        puts("");
    }
    cout<<str;
}


#include <iostream>
#include<string>
using namespace std;
int main() {
int n,m; cin>>n>>m;
bool flag=true;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
if(i%2!=0) cout<<"#";
else
{
if((j==1&&!flag)||(j==m&&flag)) cout<<"#";
else cout<<".";
}
cout<<endl;

if(i%2==0) flag=!flag;
}

return 0;
}


#include <iostream>
using namespace std;
int main(){

    int t,n,m;
    cin>>t>>n>>m;
    for (int i=1;i<=n;i++){

        for(int j=1;j<=m;j++)
        {

            if (((i/2)%2!=0)&&j==m){

                cout<<"#";
              else   if (((i/2)%2==0)&&j==1){
                 cout<<"#";
                else  if (i%2!=0)
        cout<<"#";
                 else cout<<".";
            }
        }

    }
     cout<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;
int main(){

	int n,m;
	cin>>n>>m;
	bool last=true;
	for (int i=1;i<=n;i++)
	{

		for (int j=1 ; j<=m ;j++)
		{

			if(i%2!=0)
			cout<<"#";
			else {
				if ((j==1 && !last )||(j==m && last))
					cout<<"#";
				else
				cout<<".";
			}
			if(i%2==0)
			last=!last;
		} cout<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(){

    int t,n,m;
    cin>>t>>n>>m;
    for (int i=1;i<=n;i++){

        for(int j=1;j<=m;j++)
        {

            if (((i/2)%2!=0)&&j==m)

                cout<<"#";
              else   if (((i/2)%2==0)&&j==1)
                 cout<<"#";
                else  if (i%2!=0)
              cout<<"#";
                 else cout<<".";

    }
        cout<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;
int main(){

	int n,m;
	cin>>n>>m;
	bool last=true;
	for (int i=1;i<=n;i++)
	{

		for (int j=1 ; j<=m ;j++)
		{
			if(i%2==1)
			cout<<"#";
			else {
				if ((j==1 && !last )||(j==m && last))
					cout<<"#";
				else
				cout<<".";
			}
			if(i%2==0)
			last=!last;
		} cout<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(){

	int n,m;
	cin>>n>>m;
	bool last=true;
	for (int i=1;i<=n;i++)//raw
	{

		for (int j=1 ; j<=m ;j++)//colom
		{

			if(i%2!=0)
			cout<<"#";
			else {
				if ((j==1 && !last )||(j==m && last))
					cout<<"#";
				else
				cout<<".";
			}
			if(i%2==0)// mrgt 3  sater zwje yger alshart
			last=!last;
		} cout<<endl;//for prent ech one in a rae
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main(){

	int n,m;
	cin>>n>>m;
	bool last=true;
	for (int i=1;i<=n;i++)
	{

		for (int j=1 ; j<=m ;j++)
		{
			if(i%2==1)
			cout<<"#";
			else {
				if ((j==1 && !last )||(j==m && last))
					cout<<"#";
				else
				cout<<".";
			}
			if(i%2==0)
			last=!last;
		} cout<<endl ;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(){

    int t,n,m;
    cin>>t>>n>>m;
    for (int i=1;i<=n;i++){

        for(int j=1;j<=m;j++)
        {

            if (((i/2)%2!=0)&&j==m){

                cout<<"#";
              else   if (((i/2)%2==0)&&j==1){
                 cout<<"#";
                else  if (i%2!=0)
        cout<<"#";
                 else cout<<".";
            }
        }

    }

    return 0;
}


#include <iostream>
using namespace std;
int main(){

    int t,n,m;
    cin>>t>>n>>m;
    for (int i=1;i<=n;i++){

        cout<<".";
        else
        for(int j=1;j<=m;j++)
        {

            if (((i/2)%2!=0)&&j==m){

                cout<<"#";
              else   if (((i/2)%2==0)&&j==1){
                 cout<<"#";
                else  if (i%2!=0)
        cout<<"#";
                 else cout<<".";
            }
        }

    }

    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        if(i%2!=0){
        for(int k=0;k<m;k++){
                cout<<"#";
        }
        cout<<"\n";
        }
        else{
            for(int k=0;k<m-1;k++){
                cout<<".";
            }
            cout<<"#"<<"\n";
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        if(i%2!=0)
        for(int k=0;k<m;k++){
                cout<<"#"<<"\n";
        }
        else{
            for(int k=0;k<m-1;k++){
                cout<<".";
            }
            cout<<"#"<<"\n";
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        if(i%2!=0)
        for(int k=0;k<m;k++){
                cout<<"#";
        }
        else{
            for(int k=0;k<m-1;k++){
                cout<<".";
            }
            cout<<"#";
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        if(i%2!=0)
        for(int k=0;k<m;k++){
                cout<<"#";
        }
        cout<<"\n";
        else{
            for(int k=0;k<m-1;k++){
                cout<<".";
            }
            cout<<"#"<<"\n";
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long int n,m;
    cin>>n>>m;
    int flag=0;
    for(int i=1;i<=n;i++){
        if(i%2!=0){
        for(int k=0;k<m;k++){
                cout<<"#";
        }
        cout<<"\n";
        }
        else if(i%2==0&&flag==0){
            for(int k=0;k<m-1;k++){
                cout<<".";
            }
            cout<<"#"<<"\n";
            flag=1;
        }
        else{
            cout<<"#";
            for(int k=0;k<m-1;k++){
                cout<<".";
            }
            cout<<"\n";
            flag=0;
        }
    }
    return 0;
}


#include <iostream>
#include<string>
#include<array>
using namespace std;

int main()
{
	int n, i, j , m, k =1;
	cin >> n >> m;
	int arr[n][m];
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(i%2 == 0){
				cout << '#';
			}
			else if(k == 2){
				if(j%m == 0) cout << '#';
				else cout << '.';
				k--;
			}
			else if(k == 1){
				if(j%m == 2) cout << '#';
				else cout << '.';
				k++;
			}
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<array>
using namespace std;

int main()
{
	int n, i, j , m, k =1;
	cin >> n >> m;
	int arr[n][m];
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(i%2 == 0){
				cout << '#';
			}
			else{
			if(k%2 == 0){
				if(j == 0) {
					cout << '#';

				}
				else cout << '.';

			}
			else if(k%2 == 1){
				if(j == m-1) {
					cout << '#';
				}
				else cout << '.';

			}
			k++;
			}

		}
		cout << endl;

	}
	return 0;
}


#include <iostream>
#include<string>
#include<array>
using namespace std;

int main()
{
	int n, i, j , m, k =1;
	cin >> n >> m;
	int arr[n][m];
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(i%2 == 0){
				cout << '#';
			}
			else if(k == 2){
				if(j%m == 0) {
					cout << '#';
					k--;
				}
				else cout << '.';

			}
			else if(k == 1){
				if(j%m == m-1) {
					cout << '#';
					k++;
				}
				else cout << '.';

			}
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<array>
using namespace std;

int main()
{
	int n, i, j , m, k =1;
	cin >> n >> m;
	int arr[n][m];
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(i%2 == 0){
				cout << '#';
			}

			else if(k%2 == 0){
				if(j == 0) {
					cout << '#';

				}
				else cout << '.';

			}
			else if(k%2 == 1){
				if(j == m-1) {
					cout << '#';
				}
				else cout << '.';

			}

		}
			if(i%2 != 0) k++;
		cout << endl;

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m,i,j;
 cin>>n>>m;
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   if(n%2==0 || j==m-1)
   cout<<"#";
   else
   cout<<".";
  }
  cout<<"\n";
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std
int main()
{
 int n,m,i,j;
 cin>>n>>m;
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   if(i%2==0 || j==m-1)
   cout<<"#";
   else
   cout<<".";
  }
  cout<<"\n";
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m,i,j,k,c=0;
 cin>>n>>m;
 k=m-1;
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   if(i%2==0)
   cout<<"#";
   else if(j==k)
   {
    cout<<"#";
    c++;
    }
   else
   cout<<".";
  }
  if(i%2!=0){
  if(k==m-1)
  k=0;
  else
  k=m-1;
  }
  cout<<"\n";
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m,i,j;
 cin>>n>>m;
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   if(i%2==0 || j==m-1)
   cout<<"#";
   else
   cout<<".";
  }
  cout<<"\n";
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m,i,j,k,c=0;
 cin>>n>>m;
 k=m-1;
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   if(i%2==0)
   cout<<"#";
   else if(j==k)
   {
    cout<<"#";
    c++;
    }
   else
   cout<<".";
  }
  if(c%2==0)
  k=0;
  else
  k=m-1;
  cout<<"\n";
 }
 return 0;
}


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b; cin >> a >> b;
    char ch[a][b];
    for(int j=0;j<a;j++)
    	for(int i=0;i<b;i++){
	      ch[j][i]='#';
    }
    bool tr=false;
    for(int i=0;i<b;i++)
        ch[1][i]='.';
    ch[1][b-1]='#';
    for(int j=1;j<(a-1/2);j++)
    {
        for(int i=0;i<b;i++)
        {
            ch[j*2+1][i]='.';
        }
        if(tr){
            ch[j*2+1][b-1]='#';
            tr=!tr;
        }
        else{
            ch[j*2+1][0]='#';
            tr=!tr;
        }
    }
    for(int j=0;j<a;j++){
    	for(int i=0;i<b;i++)
        	cout<<ch[j][i];
        cout<<endl;
    }
}


#include <string>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int a, b; cin >> a >> b;
	string a_str;
	string b_str;
	string c_str;
	for (int i = 0; i < b; i++)
		a_str += '#';
	for (int i = 0; i < b; i++)
		b_str += '.';
	b_str[b - 1] = '#';
	for (int i = 0; i < b; i++)
		c_str += '.';
	c_str[0] = '#';
	cout << a_str << endl;
	bool t = true;
	for (int i = 0; i < (a - 1) / 2; i++)
	{
		if (t) { cout << b_str << endl; t = !t; }
		else {cout << c_str << endl; t = !t;}
		cout << a_str << endl;
	}
}


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b; cin >> a >> b;
    char ch[a][b];
    for(int j=0;j<a;j++)
    	for(int i=0;i<b;i++){
	      ch[j][i]='#';
    }
    bool tr=false;
    for(int i=0i<b;i++)
        ch[1][i]='.';
    ch[1][b-1]='#';
    for(int j=1;j<(a-1)/2;j++)
    {
        for(int i=0;i<b;i++)
        {
            ch[j*2+1][i]='.';
        }
        if(tr){
            ch[j*2+1][b-1]='#';
            tr=!tr;
        }
        else{
            ch[j*2+1][0]='#';
            tr=!tr;
        }
    }
    for(int j=0;j<a;j++){
    	for(int i=0;i<b;i++)
        	cout<<ch[j][i];
        cout<<endl;
    }
}


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b; cin >> a >> b;
    char ch[a][b];
    for(int j=0;j<a;j++)
    	for(int i=0;i<b;i++){
	      ch[j][i]='#';
    }
    bool tr=false;
    for(int i=0;i<b;i++)
        ch[1][i]='.';
    ch[1][b-1]='#';
    for(int j=1;j<(a-1)/2;j++)
    {
        for(int i=0;i<b;i++)
        {
            ch[j*2+1][i]='.';
        }
        if(tr){
            ch[j*2+1][b-1]='#';
            tr=!tr;
        }
        else{
            ch[j*2+1][0]='#';
            tr=!tr;
        }
    }
    for(int j=0;j<a;j++){
    	for(int i=0;i<b;i++)
        	cout<<ch[j][i];
        cout<<endl;
    }
}


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b; cin >> a >> b;
    char ch[a][b];
    for(int j=0;j<a;j++)
    	for(int i=0;i<b;i++){
	      ch[j][i]='#';
    }
    bool tr=false;
    for(int i=0i<b;i++)
        ch[1][i]='.';
    ch[1][b-1]='#';
    for(int j=1;j<(a-1/2);j++)
    {
        for(int i=0;i<b;i++)
        {
            ch[j*2+1][i]='.';
        }
        if(tr){
            ch[j*2+1][b-1]='#';
            tr=!tr;
        }
        else{
            ch[j*2+1][0]='#';
            tr=!tr;
        }
    }
    for(int j=0;j<a;j++){
    	for(int i=0;i<b;i++)
        	cout<<ch[j][i];
        cout<<endl;
    }
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[m][n];
    for(int i=1;i<=m;++i)
    {
        for(int j=1;j<=n;++j)
        {
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0) snake[i][1]='#';
            else if(i%2==0&&i%4!=0) snake[i][m]='#';
            else snake[i][j]='.';
        }
    }
    for(int i=1;i<=m;++i)
    {
        for(int j=1;j<=n;++j)
        {
            cout<<snake[i][j];
            if(j==n) break;
            cout<<endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            snake[i][j]='.';
            if(i%2!=0) {snake[i][j]='#';}
            else if(i%2==0&&i%4==0&&j==1) {snake[i][1]='#';}
            else if(i%2==0&&i%4!=0&&j==m) {snake[i][m]='#';}
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
        }
        if(i==n) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[m][n];
    for(int i=1;i<=m;++i)
    {
        for(int j=1;j<=n;++j)
        {
            if(j%2!=0) snake[j][i]='#';
            else if(j%2==0&&j%4==0) snake[j][1]='#';
            else if(j%2==0&&j%4!=0) snake[j][m]='#';
            else snake[j][i]='.';
        }
    }
    for(int i=1;i<=m;++i)
    {
        for(int j=1;j<=n;++j)
        {
            cout<<snake[j][i];
        }
        if(i=m) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0) snake[i][1]='#';
            else if(i%2==0&&i%4!=0) snake[i][m]='#';
            else snake[i][j]='.';
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
        }
        if(i==n) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0) snake[i][1]='#';
            else if(i%2==0&&i%4!=0) snake[i][m]='#';
            else snake[i][j]='.';
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
            if(j==m) break;
            cout<<endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0) snake[i][1]='#';
            else if(i%2==0&&i%4!=0) snake[i][m]='#';
            else if(i%2==0&&j!=1&&j1=m) snake[i][j]='.';
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
        }
        if(i==n) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            snake[i][j]='.';
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0&&j==1) snake[i][1]='#';
            else if(i%2==0&&i%4!=0&&j==m) snake[i][m]='#';
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
        }
        if(i==n) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0) snake[i][1]='#';
            else if(i%2==0&&i%4!=0) snake[i][m]='#';
            else if(i%2==0&&j!=1&&j!=m) snake[i][j]='.';
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
        }
        if(i==n) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0&&j==1) snake[i][1]='#';
            else if(i%2==0&&i%4!=0&&j==m) snake[i][m]='#';
            else snake[i][j]='.';
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
        }
        if(i==n) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    char snake[n][m];
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(i%2!=0) snake[i][j]='#';
            else if(i%2==0&&i%4==0&&j==1) snake[i][1]='#';
            else if(i%2==0&&i%4!=0&&j==m) snake[i][m]='#';
            else if(i%2==0&&j!=1&&j!=m) snake[i][j]='.';
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cout<<snake[i][j];
        }
        if(i==n) break;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 0;
    for (i = 1; i < n + 1; ++i)
    {
        for (j = 1; j < m + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
                test++;
            }
            else
            {
                if (test % 2 != 0)
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == m)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
            }
        }

        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 1;
    for (i = 1; i < m + 1; ++i)
    {
        for (j = 1; j < n + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
            }
            else
            {
                if (test % 2 != 0)
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == n)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                test++;
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 0;
    for (i = 1; i < n + 1; ++i)
    {
        for (j = 1; j < m + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
                test++;
            }
            else
            {
                if (test % 2 == 0)
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == m)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
            }
        }

        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 1;
    for (i = 1; i < n + 1; ++i)
    {
        for (j = 1; j < m + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
            }
            else
            {
                if (test % 2 != 0)
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == m)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
            }
        }
        test++;
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 0;
    for (i = 1; i < n + 1; ++i)
    {
        for (j = 1; j < m + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
            }
            else
            {
                if (test % 2 != 0)
                {
                    if (j == m)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
            }
        }
        if (i % 2 != 0)
        {
            test++;
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 1;
    for (i = 1; i < m + 1; ++i)
    {
        for (j = 1; j < n + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
            }
            else
            {
                if (test % 2 == 0)
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == n)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                test++;
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> m >> n;
    test = 1;
    for (i = 1; i < m + 1; ++i)
    {
        for (j = 1; j < n + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
            }
            else
            {
                if (test % 2 == 0)
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == n)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                test++;
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 1;
    for (i = 1; i < n + 1; ++i)
    {
        for (j = 1; j < m + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
            }
            else
            {
                if (test % 2 == 0)
                {
                    if (j == m)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                test++;
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n, i, j, m, test;
    cin >> n >> m;
    test = 1;
    for (i = 1; i < n + 1; ++i)
    {
        for (j = 1; j < m + 1; j++)
        {
            if (i % 2 != 0)
            {
                cout << "#";
            }
            else
            {
                if (test % 2 == 0)
                {
                    if (j == 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (j == m)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                test++;
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int a=3;
    bool q=0,w=0;
    for(int i=1; i<=n; i++)
    {
        if(w==0)
            for(int j=1; j<=m; j++)
            {
                cout<<"#";
                w=1;
            }
        cout<<endl;
        if(q==0&&a<=m)
        {
            for(int j=1; j<m; j++)
                cout<<".";
            cout<<"#";
            q=1;
            w=0; a+=2;
            cout<<endl;
        }
        else if(q==1&&a<=m)
        {
            cout<<"#";
            q=0; a+=2;
            w=0;
            for(int j=2; j<=m; j++)
                cout<<".";
            cout<<endl;
        }

    }

}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    bool q=0;
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        if(i%2!=0)
        {
            for(int j=1; j<=m; j++) cout<<"#";
            if(i!=n)cout<<endl;
        }
        else if(q==0)
        {
            for(int j=1; j<=m; j++) if(j!=m) cout<<".";
                else cout<<"#";
            q=1;
            cout<<endl;
        }
         else if(q==1)
        {
            for(int j=1; j<=m; j++) if(j==1) cout<<"#";
                else cout<<".";
            q=0;
            cout<<endl;
        }
    }
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int a=2;
    bool q=0,w=0;
    for(int i=1; i<=n; i++)
    {
        if(w==0)
            for(int j=1; j<=m; j++)
            {
                cout<<"#";
                w=1;
            }
        cout<<endl;
        if(q==0&&a<=m)
        {
            for(int j=1; j<m; j++)
                cout<<".";
            cout<<"#";
            q=1;
            w=0; a+=2;
            cout<<endl;
        }
        else if(q==1&&a<=m)
        {
            cout<<"#";
            q=0; a+=2;
            w=0;
            for(int j=2; j<=m; j++)
                cout<<".";
            cout<<endl;
        }

    }

}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    bool q=0;
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        if(i%2!=0)
        {
            for(int j=1; j<=m; j++) cout<<"#";
            if(i!=n)cout<<endl;
        }
        else if(q==0)
        {
            for(int j=1; j<=m; j++) if(j!=m) cout<<"*";
                else cout<<"#";
            q=1;
            cout<<endl;
        }
         else if(q==1)
        {
            for(int j=1; j<=m; j++) if(j==1) cout<<"#";
                else cout<<"*";
            q=0;
            cout<<endl;
        }
    }
}


#include <iostream>
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define FX(n) fixed<<setprecision(n)
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
    IO
        int n , m ;
        cin>> n >> m ;
        for (int i=1 ; i<=n ; i++)
        {
            for (int j=1 ; j<=m ; j++)
            {
                if (i%2 !=0 )
                cout<<'#';
                else
                {
                     if (i%4==0)
                    {
                         if(j==1)
                         cout<<'#' ;
                         else
                         cout<<'.' ;
                    }
                    else
                      if(j!=m)
                      cout<<'.';
                }
            }
            if(i%4==0)
                cout<<endl ;
            else if(i%2==0)
            {
                cout<<'#' ;
                cout<<endl ;
            }
            else
                cout<<endl ;

        }
    re 0 ;
}


#include <iostream>
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define FX(n) fixed<<setprecision(n)
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
    IO
        int n , m ;
        cin>> n >> m ;
        for (int i=1 ; i<=n ; i++)
        {
            cout<<endl ;
            for (int j=1 ; j<=m ; j++)
            {
                if (i%2 !=0 )
                cout<<'#';
                else
                {
                     if (i%4==0)
                    {
                         if(j==1)
                         cout<<'#' ;
                         else
                         cout<<'.' ;
                    }
                    else
                      if(j!=m)
                      cout<<'.';
                }
            }
            if(i%4==0)
                cout<<endl ;
            else
            cout<<'#' ;

        cout<<endl ;
        }
    re 0 ;
}


#include <iostream>
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define FX(n) fixed<<setprecision(n)
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
    IO
        int n , m ;cin>> n >> m ;
        for (int i=1 ; i<=n ; i++)
        {
            for (int j=1 ; j<=m ; j++)
            {
                if (i%2 !=0 )
                cout<<'#';
                else
                {
                     if (i%4==0)
                      (j==1)?cout<<'#' :cout<<'.' ;
                    else
                      if(j!=m)
                      cout<<'.';
                }
            }
            if(i%4==0)
                cout<<endl ;
            else if(i%2==0)
               cout<<'#' <<endl;
            else
                cout<<endl ;
        }
    re 0 ;
}


#include <iostream>
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define FX(n) fixed<<setprecision(n)
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
    IO
        int n , m ;cin>> n >> m ;
        for (int i=1 ; i<=n ; i++)
        {
            for (int j=1 ; j<=m ; j++)
            {
                if (i%2 !=0 )
                cout<<'#';
                else
                {
                     if (i%4==0)
                      (j==1)?cout<<'#' :cout<<'.' ;
                    else
                      if(j!=m)
                      cout<<'.';
                }
            }
            if(i%4==0)
                cout<<endl ;
            else if(i%2==0)
               cout<<'#' ;cout<<endl ;
            else
                cout<<endl ;
        }
    re 0 ;
}


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

  int main()
  {
     int n,m,i,r,j;
     cin>>n>>m;
     r=1;
     bool I= false;

     while(r<=n)
     {
         if(r%2==1)
         {
             for(i=0;i<m;i++)
                 cout<<"#";
             cout<<endl;
         }
         else if(r%2==0&&I==false)
         {
                for(j=0;j<m-1;j++)
                cout<<".";
                cout<<"#"<<endl;
                1==true;
         }
         else
         {
             cout<<"#";
              for(j=0;j<m-1;j++)
                cout<<".";
              cout<<endl;
              I==false;

         }
         r++;
     }

        return 0;
     }


import java.io.IOException;
import java.util.InputMismatchException;

/**
 * Created by jizhe on 2016/1/30.
 */
public class NoToPalindromes {
    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }

    public static void main(String[] args) {
        //Scanner in = new Scanner(new BufferedInputStream(System.in));
        FasterScanner in = new FasterScanner();
        StringBuilder out = new StringBuilder();

        int N = in.nextInt();
        int P = in.nextInt();
        StringBuilder s = new StringBuilder(in.nextString());

        int pos = N-1;
        boolean carry = false;
        while( pos != -1 && pos != N )
        {
            int curValue;
            if( carry )
            {
                curValue = -1;
            }
            else
            {
                curValue = s.charAt(pos)-'a';
            }

            //System.out.printf("pos: %d, curValue: %c\n", pos, 'a'+curValue);

            if( curValue+1 > P-1 )
            {
                //System.out.printf("shift over\n");
                pos--;
                carry = false;
            }
            else
            {
                char c = (char)('a'+curValue+1);
                s.setCharAt(pos, c);

                if( pos >= 1 )
                {
                    if( curValue+1 == s.charAt(pos-1)-'a' )
                    {
                        //System.out.printf("equal with pos: %d\n", pos-1);
                        carry = false;
                    }
                    else
                    {
                        if( pos >= 2 )
                        {
                            if( curValue+1 == s.charAt(pos-2)-'a' )
                            {
                                //System.out.printf("equal with pos: %d\n", pos-2);
                                carry = false;
                            }
                            else
                            {
                                pos++;
                                carry = true;
                            }
                        }
                        else
                        {
                            pos++;
                            carry = true;
                        }
                    }
                }
                else
                {
                    //System.out.printf("");
                    pos++;
                    carry = true;
                }
            }
        }

        if( pos == -1 )
        {
            System.out.printf("NO\n");
        }
        else
        {
            System.out.printf("%s\n", s.toString());
        }
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ilyakor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();
        String s = in.nextToken();
        int[] a = new int[n];
        int[] allow = new int[n];
        for (int i = 0; i < n; ++i) {
            boolean[] avail = new boolean[k];
            Arrays.fill(avail, true);
            for (int j = 1; j <= 2 && i - j >= 0; ++j) {
                avail[s.charAt(i - j) - 'a'] = false;
            }
            int cur = s.charAt(i) - 'a';
            int cnt = 0;
            for (int j = 0; j < cur; ++j)
                if (avail[j])
                    ++cnt;
            a[i] = cnt;

            cnt = 0;
            for (int j = 0; j < k; ++j)
                if (avail[j])
                    ++cnt;
            allow[i] = cnt;
        }
        int pos = n - 1;
        while (pos >= 0 && a[pos] + 1 >= allow[pos]) {
            a[pos] = 0;
            --pos;
        }
        if (pos < 0) {
            out.printLine("NO");
            return;
        }
        ++a[pos];
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < n; ++i) {
            boolean[] avail = new boolean[k];
            Arrays.fill(avail, true);
            for (int j = 1; j <= 2 && i - j >= 0; ++j) {
                avail[res.charAt(i - j) - 'a'] = false;
            }
            int cur = 0;
            int cnt = 0;
            while (cnt <= a[i]) {
                if (avail[cur])
                    ++cnt;
                if (cnt > a[i]) break;
               ++cur;
            }
            res.append((char)(cur + 'a'));
        }
        out.printLine(res.toString());
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public static boolean isSpace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
        if (count == -1) {
            throw new InputMismatchException();
        }
        try {
            if (cur >= count) {
                cur = 0;
                count = stream.read(buffer);
                if (count <= 0)
                    return -1;
            }
        } catch (IOException e) {
            throw new InputMismatchException();
        }
        return buffer[cur++];
    }

    public int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    public String nextToken() {
        int c = readSkipSpace();
        StringBuilder sb = new StringBuilder();
        while (!isSpace(c)) {
            sb.append((char) c);
            c = read();
        }
        return sb.toString();
    }

    public int nextInt() {
        int sgn = 1;
        int c = readSkipSpace();
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res = res * 10 + c - '0';
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class P464A {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}

	static class Task {
		int add(StringBuffer s, int pos, int bas) {
			char next = (char) (s.charAt(pos) + 1);
			while ((pos - 1 >= 0 && s.charAt(pos - 1) == next) || (pos - 2 >= 0 && s.charAt(pos - 2) == next))
				next++;
			if (pos == 0 && next - 'a' >= bas)
				return -1;
			while (next - 'a' >= bas) {
				next = 'a';
				if (add(s, pos - 1, bas) != 0) {
					return -1;
				}
				while ((pos - 1 >= 0 && s.charAt(pos - 1) == next) || (pos - 2 >= 0 && s.charAt(pos - 2) == next))
					next++;
			}
			s.setCharAt(pos, next);
			return 0;
		}

		public void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt(), p = in.nextInt();
			StringBuffer s;
			s = new StringBuffer(in.nextLine());
			if (add(s, n - 1, p) != -1) {
				System.out.printf("%s\n", s);
			} else {
				System.out.printf("NO\n");
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Arrays.fill;
import java.util.Collections;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

//<editor-fold defaultstate="collapsed" desc="Main">
public class Solution {
// https://netbeans.org/kb/73/java/editor-codereference_ru.html#display
    private void run() {
        try {
            Locale.setDefault(Locale.US);
        } catch (Exception e) {
        }
        boolean oj = true;
        try {
            oj = System.getProperty("MYLOCAL") == null;
        } catch (Exception e) {
        }

        if (oj) {
            sc = new FastScanner(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        } else {
            try {
                sc = new FastScanner(new FileReader("input.txt"));
                out = new PrintWriter(new FileWriter("output.txt"));
            } catch (IOException e) {
                MLE();
            }
        }
        Solver s = new Solver();
        s.sc = sc;
        s.out = out;
        s.solve();
        if (!oj) {
            err.println("Time: " + (System.currentTimeMillis() - timeBegin) / 1e3);
            err.printf("Mem: %d\n", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);
        }
        out.flush();
    }

    private void show(int[] arr) {
        for (int v : arr) {
            err.print(" " + v);
        }
        err.println();
    }

    public static void exit() {
        err.println("Time: " + (System.currentTimeMillis() - timeBegin) / 1e3);
        out.flush();
        out.close();
        System.exit(0);
    }

    public static void MLE() {
        int[][] arr = new int[1024 * 1024][];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new int[1024 * 1024];
        }
    }

    public static void main(String[] args) {
        new Solution().run();
    }

    static long timeBegin = System.currentTimeMillis();
    static FastScanner sc;
    static PrintWriter out;
    static PrintStream err = System.err;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="FastScanner">
class FastScanner {

    BufferedReader br;
    StringTokenizer st;

    FastScanner(InputStreamReader reader) {
        br = new BufferedReader(reader);
        st = new StringTokenizer("");
    }

    String next() {
        while (!st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException ex) {
                Solution.MLE();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }
    double nextDouble() {
        return Double.parseDouble(next());
    }
}
//</editor-fold>

final class Slider{
    int l, r;
    long[] arr;
    ArrayDeque<Long> Q;

    public Slider(int l, int r, long[] arr) {
        this.l = l;
        this.r = r;
        this.arr = arr;
        Q = new ArrayDeque<>();
        for( int i = max(l,1); i <= min(arr.length-1,r); ++i ){
            add( arr[i] );
        }
    }

    void add( long val ){
        while( !Q.isEmpty() && Q.getLast() < val )
            Q.removeLast();
        Q.add(val);
    }

    void next(){
        if( 1 <= l && l < arr.length && Q.getFirst() == arr[l] )
            Q.removeFirst();
        ++l;
        //
        if( 1 <= r+1 && r+1 < arr.length  )
            add( arr[r+1] );
        ++r;
    }

    long getMax(){
//        long max = Long.MIN_VALUE;
//        for( int i = max(l,1); i <= min(arr.length-1,r); ++i )
//            max = max( max, arr[i] );
//        if( max != Q.getFirst() )
//            Solution.MLE();
        return Q.getFirst();
    }
}

class Pair{
    int a, b;

    public Pair(int a, int b) {
        this.a = a;
        this.b = b;
    }
}

class Solver {
    void ass(boolean OK) { if(!OK)Solution.MLE(); }
    FastScanner sc;
    PrintWriter out;
    static PrintStream err = System.err;

    int n, p;
    char[] str;

    boolean set( int i, char beg ){
        for( char ch = beg; ch <= 'a' + p - 1; ++ch ){
            if( 0 <= i-1 && ch != str[i-1] &&
                0 <= i-2 && ch != str[i-2] ){
                str[i] = ch;
                return true;
            }
        }
        return false;
    }

    void solve() {
        n = sc.nextInt();
        p = sc.nextInt();
        str = sc.next().toCharArray();
        for( int i = str.length-1; 0 <= i; --i ){
            if( set(i,(char)(str[i]+1)) ){
                err.println(i);
                for (int j = i + 1; j < str.length; j++) {
                    set(j,'a');
                }
                out.println(new String(str));
                return;
            }
        }
        out.println("NO");
    }

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Arrays.fill;
import java.util.Collections;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

//<editor-fold defaultstate="collapsed" desc="Main">
public class Solution {
// https://netbeans.org/kb/73/java/editor-codereference_ru.html#display
    private void run() {
        try {
            Locale.setDefault(Locale.US);
        } catch (Exception e) {
        }
        boolean oj = true;
        try {
            oj = System.getProperty("MYLOCAL") == null;
        } catch (Exception e) {
        }

        if (oj) {
            sc = new FastScanner(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        } else {
            try {
                sc = new FastScanner(new FileReader("input.txt"));
                out = new PrintWriter(new FileWriter("output.txt"));
            } catch (IOException e) {
                MLE();
            }
        }
        Solver s = new Solver();
        s.sc = sc;
        s.out = out;
        s.solve();
        if (!oj) {
            err.println("Time: " + (System.currentTimeMillis() - timeBegin) / 1e3);
            err.printf("Mem: %d\n", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);
        }
        out.flush();
    }

    private void show(int[] arr) {
        for (int v : arr) {
            err.print(" " + v);
        }
        err.println();
    }

    public static void exit() {
        err.println("Time: " + (System.currentTimeMillis() - timeBegin) / 1e3);
        out.flush();
        out.close();
        System.exit(0);
    }

    public static void MLE() {
        int[][] arr = new int[1024 * 1024][];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new int[1024 * 1024];
        }
    }

    public static void main(String[] args) {
        new Solution().run();
    }

    static long timeBegin = System.currentTimeMillis();
    static FastScanner sc;
    static PrintWriter out;
    static PrintStream err = System.err;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="FastScanner">
class FastScanner {

    BufferedReader br;
    StringTokenizer st;

    FastScanner(InputStreamReader reader) {
        br = new BufferedReader(reader);
        st = new StringTokenizer("");
    }

    String next() {
        while (!st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException ex) {
                Solution.MLE();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }
    double nextDouble() {
        return Double.parseDouble(next());
    }
}
//</editor-fold>

final class Slider{
    int l, r;
    long[] arr;
    ArrayDeque<Long> Q;

    public Slider(int l, int r, long[] arr) {
        this.l = l;
        this.r = r;
        this.arr = arr;
        Q = new ArrayDeque<>();
        for( int i = max(l,1); i <= min(arr.length-1,r); ++i ){
            add( arr[i] );
        }
    }

    void add( long val ){
        while( !Q.isEmpty() && Q.getLast() < val )
            Q.removeLast();
        Q.add(val);
    }

    void next(){
        if( 1 <= l && l < arr.length && Q.getFirst() == arr[l] )
            Q.removeFirst();
        ++l;
        //
        if( 1 <= r+1 && r+1 < arr.length  )
            add( arr[r+1] );
        ++r;
    }

    long getMax(){
//        long max = Long.MIN_VALUE;
//        for( int i = max(l,1); i <= min(arr.length-1,r); ++i )
//            max = max( max, arr[i] );
//        if( max != Q.getFirst() )
//            Solution.MLE();
        return Q.getFirst();
    }
}

class Pair{
    int a, b;

    public Pair(int a, int b) {
        this.a = a;
        this.b = b;
    }
}

class Solver {
    void ass(boolean OK) { if(!OK)Solution.MLE(); }
    FastScanner sc;
    PrintWriter out;
    static PrintStream err = System.err;

    int n, p;
    char[] str;

    boolean set( int i, char beg ){
        for( char ch = beg; ch <= 'a' + p - 1; ++ch ){
            if( ( i-1 < 0 || ch != str[i-1]) &&
                ( i-2 < 0 || ch != str[i-2]) ){
                str[i] = ch;
                return true;
            }
        }
        return false;
    }

    void solve() {
        n = sc.nextInt();
        p = sc.nextInt();
        str = sc.next().toCharArray();
        for( int i = str.length-1; 0 <= i; --i ){
            if( set(i,(char)(str[i]+1)) ){
                err.println(i);
                for (int j = i + 1; j < str.length; j++) {
                    set(j,'a');
                }
                out.println(new String(str));
                return;
            }
        }
        out.println("NO");
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //(new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;
        //PrintWriter pw = new PrintWriter("output.out", "UTF-8");

        tk = new StringTokenizer(in.readLine());
        int n = parseInt(tk.nextToken()), p = parseInt(tk.nextToken()) - 1;
        String str = in.readLine();

        if((p==1 && n>1) || (p==2 && n>2)) {
            System.out.println("NO");
            return;
        }

        str = "00" + str + "00";
        boolean f = true;

        char[] s = str.toCharArray();

        int i;
        for(i=s.length-3; i>=2; i--) {
            int k = s[i]-'a'+1;
            for(; k<=p; k++) {
                char c = (char)(k+'a');
                if(c!=s[i+1] && c!=s[i+2] && c!=s[i-1] && c!=s[i-2]) {
                    s[i] = c;
                    break;
                }
            }

            if(k>p && i>2) s[i] = 'a';
            else if(k>p) {
                System.out.println("NO");
                return;
            } else break;
        }
        i++;

        out :
        for(; i<=s.length-3; i++) {
            int k=s[i]-'a';
            for(; k<=p; k++) {
                char c = (char)(k+'a');
                if(c!=s[i-1] && c!=s[i-2]) {
                    s[i] = c;
                    break;
                }
            }

            if(k > p) {
                f = false;
                break;
            }
        }

        String s2 = valueOf(s).replace("0", "");
        str = str.replace("0", "");
        if (f && !s2.equals(str)) {
            System.out.println(s2);
        } else {
            System.out.println("NO");
        }
    }

}