/********include********/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
//#include <atcoder/all>

/***/
//#include <iomanip>
//#include <cmath>
#include <bits/stdc++.h>


/********define********/
const int MAX = 510000;
const int MOD = 1000000007;


#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define REP(i,n,x) for(long long i=n;i<x;i++)
#define REPN(i,n,x) for(long long i=n+1;i<x;i++)

#define pr printf
#define re return
#define mod 1000000007
//#define mod 998244353
#define inf  INT_MAX//19桁
#define INF 1e18+5//19桁
const double PI=3.14159265358979323846;
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define all(x) (x).begin(),(x).end()

typedef long long int ll;
typedef pair<long long, long long> P;


/********変数宣言********/
//vector<long long> g[200020];
vector<pair<long long,long long>> g[200020];
ll s[200020];
bool used[200020];
//bool dp[100005];

ll A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Q,R,S,T,U,V,W,X,Y,Z;
double dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ;


string sa,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl,sm,sn,so,sp,sq,sr,ss, su,sv,sw,sx,sy,sz;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>N;cin>>M;

	vector<string>v(M);
	
	vector<pair<long long, string> > p(M);
	//sort(p.begin(), p.end());
	//sort(p.begin(), p.end(),greater<pair<long long,long long> >());
	
	rep(j,M){
		cin>>v[j];
	}
	rep(i,M){
		p[i].fi=v[i].size();
		p[i].se=v[i];
	}
	//sort(p.begin(), p.end());
	ll check;
	check=0;
	ll i;
	i=0;
	ll flg;
	while(check<N*N && i<M){
		
		if(check%N!=0){
			if(p[i-1].se[p[i-1].se.size()-1]==p[i].se[0]){
				rep(j,p[i].se.size()-1){
					p[i].se[j]=p[i].se[j+1];
				}
				p[i].se.resize(p[i].se.size()-1);
			}
		}
		
		
		if(check%N+p[i].se.size()<=N){
			cout<<p[i].se;
			check+=p[i].se.size();
			if(check%N==0){
				cout<<"\n";
			}
		}
		else{
			while(check%N!=0){
				cout<<".";
				check++;
			}
			cout<<"\n";
		}
		i++;
	}
	re 0;
}

#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 2005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
string s[2005];
int h,w;
ll dp[N][N][5];

bool valid(int i,int j)
{
    return i>=0&&i<h&&j>=0&&j<w&&s[i][j]=='.';
}

ll run(int i,int j,int c)
{
    if(i==h-1&&j==w-1)
    {
        return 1;
    }
    if(dp[i][j][c]!=-1)
        return dp[i][j][c];
    ll ans=0;
    if(c==0)
    {
        if(valid(i,j+1)) ans=(ans+run(i,j+1,1));
        if(valid(i+1,j)) ans=(ans+run(i+1,j,2));
        if(valid(i+1,j+1)) ans=(ans+run(i+1,j+1,3));
    }
    else if(c==1)
    {
        ans=(ans+run(i,j,0));
        if(valid(i,j+1)) ans=(ans+run(i,j+1,1));
    }
    else if(c==2)
    {
        ans=(ans+run(i,j,0));
        if(valid(i+1,j)) ans=(ans+run(i+1,j,2));
    }
    else if(c==3)
    {
        ans=(ans+run(i,j,0));
        if(valid(i+1,j+1)) ans=(ans+run(i+1,j+1,3));
    }
    ans%=M;
    return dp[i][j][c]=ans;
}

main()
{
    memset(dp,-1,sizeof dp);
    cin>>h>>w;
    for(int i=0;i<h;i++)
        cin>>s[i];
    cout<<run(0,0,0);
}
