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

#define rep(i, a, b)        for(register int (i) = (a); (i) <= (int)(b); (i)++)
#define repd(i, b, a)       for(register int (i) = (b); (i) >= (int)(a); (i)--)
#define mset(a, x)          memset((a), (x), sizeof(a))
#define x                   first
#define y                   second

#define int                 long long    // int 变成 long long
#define LOCAL

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

// 重载to_string
template <typename A, typename B>string to_string(pair<A, B> p);template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);string to_string(const string& s) {  return '"' + s + '"';}string to_string(const char* s) {  return to_string((string) s);}string to_string(bool b) {  return (b ? "true" : "false");}string to_string(vector<bool> v) {  bool first = true;  string res = "{";  for (int i = 0; i < static_cast<int>(v.size()); i++) {    if (!first) {      res += ", ";    }    first = false;    res += to_string(v[i]);  }  res += "}";  return res;}template <size_t N>string to_string(bitset<N> v) {  string res = "";  for (size_t i = 0; i < N; i++) {    res += static_cast<char>('0' + v[i]);  }  return res;}template <typename A>string to_string(A v) {  bool first = true;  string res = "{";  for (const auto &x : v) {    if (!first) {      res += ", ";    }    first = false;    res += to_string(x);  }  res += "}";  return res;}template <typename A, typename B>string to_string(pair<A, B> p) {  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) {  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) {  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}
// 声明debug    不能打印普通数组, 自定义结构体
void debug_out() { cout << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {  cout << " " << to_string(H);  debug_out(T...);}
#ifdef LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 404
#endif
// read  ---  只能输入整数数字(int , ll)
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
    read(first);
    read(args...);
}  // read end
///////////////////////////////   ABOUT  ///////////////////////////
/*


*/
////////////////////////////// START CODE ///////////////////////

const int mod = 1e9 + 7;
const int maxn = 1000 + 10;

int n, m;

int a[maxn], b[maxn];
int vis[maxn];

void solve(){
	
	read(n, m);
	
	rep(i, 1, n){
		read(a[i]);
		vis[a[i]] ++;
	}
	rep(i, 1, m){
		read(b[i]);
		vis[b[i]] ++;
	}
	
	
	rep(i, 1, maxn){
		if(vis[i] == 1){
			cout << i << ' ';
		}
	}
	

}

signed main(){

#ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    debug("LOCAL");
#endif

    int T = 1;
    // cin >> T;
    rep(i, 1, T){
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
//using namespace __gnu_pbds;

//template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());//uniform_int_distribution<int> (l, r)

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 1003;
const int M = 1e6 + 123;
const double pi = 3.14159265359;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

char c[2][2];

int n;

void add(int &a, int b){
    a += b;
    if (a >= MOD) a -= MOD;
}

map<string, bool> w;

int cnt = 0;

void go(string s){
    if (w[s]) return;
    w[s] = 1;
    if (sz(s) == min(n, 10)){
        cnt++;
        return;
    }
    for (int i = 1; i < sz(s); i++){
        string t = s;
        t.insert(t.begin()+i, c[s[i-1]-'A'][s[i]-'A']);
        go(t);
    }
}
int f[N];
void solve(){
    cin >> n;
    f[3] = f[2] = 1;
    for (int i = 4; i <= n; i++){
        f[i] = (f[i-1] + f[i-2]) % MOD; 
    }
    //cout << n;

    for (int i = 0; i < 2; i++){
        for (int j = 0; j < 2; j++){
            char x;
            cin >> c[i][j];

        }
    }
    go("AB");
    if (n <= 10){
        cout << cnt;
        return;
    }
    if (cnt == f[10]){
        cout << f[n];
        return;
    }
    if (cnt == 1){
        cout << 1;
        return;
    }
    int ans = 1;
    for (int i = 4; i <= n; i++){
        ans = (ans+ans)%MOD;
    }
    cout << ans;
    return;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "Case #" << i << ": ";
        solve();
    }
    #ifdef KAZAKH
      //  cout << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}