#include <bits/stdc++.h> 
#define ll long long
#define F first
#define S second
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
     
ll l, r, ans, dp[(1<<20)], a[73], A[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

int main(){

	cin>>l>>r;
	
	for (ll i=l; i<=r; i++){
		for (int j=0; j<20; j++){
			if(i%A[j]==0)a[i-l]^=(1<<j);
		}
	}
	dp[0]=1;
	for (int i=0; i<r-l+1; i++){
		for (int j=0; j<(1<<20); j++){
			if((j|a[i])==(j^a[i])){
				dp[j|a[i]]+=dp[j];
			}
		}
	}
	for (int i=0; i<(1<<20); i++){
		ans+=dp[i];
	}
	cout<<ans;
}
/*
20:
2, 
3,
5, 
7, 
11, 
13, 
17, 
19, 
23, 
29, 
31, 
37, 
41, 
43, 
47, 
53, 
59, 
61, 
67, 
71,
*/
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(bool a) { cout << (a?"Yes":"No") << endl; }
void YES(bool a) { cout << (a?"YES":"NO") << endl; }
int MOD = 1e9+7;

int INF = 1000;
int N;

int diff(vector<vector<char>> &genome, string s, int h, int w, int dir) {
	int res = 0;
	if (dir == 0) {
		rep(i, s.size()) {
			if (genome[h][(w+i)%N] != s[i] && genome[h][(w+i)%N] != '.') res++;
		}
	}
	else {
		rep(i, s.size()) {
			if (genome[(h+i)%N][w] != s[i] && genome[(h+i)%N][w] != '.') res++;
		}
	}
	return res;
}

pair<int, int> find(vector<vector<char>> &genome, string s, int dir) {
	int h=-1, w=-1;
	rep(i, N) rep(j, N) {
		bool flag = true;
		if (dir == 0) {
			rep(pos, s.size()) {
				if (genome[i][(j+pos)%N] != s[pos]) flag = false;
			}
		}
		else {
			rep(pos, s.size()) {
				if (genome[(i+pos)%N][j] != s[pos]) flag = false;
			}
		}
		if (flag) {
			h = i;
			w = j;
			break;
		}
	}
	return {h, w};
}

int main(int argc, char **argv) {
	int M; cin >> N >> M;
	vector<vector<char>> genome(N, vector<char>(N, '.'));
	vector<string> s(M);
	rep(i, M) cin >> s[i];
	// sort(ALL(s), [](const string &a, const string &b) {
	// 	return a.size() < b.size();
	// });
	mt19937 r;
	shuffle(ALL(s), r);
	rep(i, s[0].size()) genome[0][i] = s[0][i];
	rep(i, M) {
		int mindiff = INF;
		int h, w, dir;
		rep(j, N) rep(k, N) {
			if (chmin(mindiff, diff(genome, s[i], j, k, 0))) {
				h = j;
				w = k;
				dir = 0;
			}
			if (chmin(mindiff, diff(genome, s[i], j, k, 1))) {
				h = j;
				w = k;
				dir = 1;
			}
		}
		if (mindiff < s[i].size()-1) {
			if (dir == 0) {
				rep(pos, s[i].size()) {
					genome[h][(w+pos)%N] = s[i][pos];
				}
			}
			else {
				rep(pos, s[i].size()) {
					genome[(h+pos)%N][w] = s[i][pos];
				}
			}
		}
	}

	vector<vector<bool>> flag(N, vector<bool>(N, false));
	rep(i, M) {
		rep(j, N) rep(k, N) {
			if (diff(genome, s[i], j, k, 0) == 0) {
				rep(pos, s[i].size()) {
					flag[j][(k+pos)%N] = true;
				}
			}
			if (diff(genome, s[i], j, k, 1) == 0) {
				rep(pos, s[i].size()) {
					flag[(j+pos)%N][k] = true;
				}
			}
		}
	}
	rep(h, N) rep(w, N) {
		if (!flag[h][w]) genome[h][w] = '.';
	}

	rep(h, N) {
		rep(w, N) {
			printf("%c", genome[h][w]);
		}
		printf("\n");
	}
}