Problem

Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules.

1. First of all, select one of your favorite strings from the list and exclude that string from the list.
2. Next, select one character string from the list in which the last character of the previously selected character string is the first character.
3. Exclude the selected string from the list.



After this, steps 2 and 3 will be repeated alternately.

Now, let's assume that this shiritori is continued until there are no more strings to select from the list in 2. At this time, I want to list all the characters that can be the "last character" of the last selected character string.

Constraints

The input satisfies the following conditions.

* $ 1 \ le N \ lt 10 ^ 4 $
* $ 1 \ le | s_i | \ lt 100 $
* $ s_i \ neq s_j (i \ neq j) $
* The string contains only lowercase letters

Input


$ N $
$ s_1 $
$ s_2 $
$ s_3 $
::
$ s_N $


The number of strings $ N $ is given on the first line.
The following $ N $ line is given a list of strings.

Output

Output the characters that can be the "last character" of the last selected character string in ascending order from a to z in lexicographical order.

Examples

Input

5
you
ate
my
hum
toast


Output

e
t
u


Input

7
she
sells
sea
shells
by
the
seashore


Output

a
e
y
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
// template <typename T> using V = vector<T>;
// template <typename T> using VV = vector<V<T>>;
// template <typename T> using VVV = vector<VV<T>>;
using VI = vector<int>;
using VVI = vector<VI>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

class SCC {
public:
  int V,K;    // 頂点数, scc後の頂点数
  VVI G;      // グラフの隣接リストの表現
  VVI rG;     // 辺の向きを逆にしたグラフ
  VVI DAG;    // scc後のグラフの隣接リストの表現
  VVI rDAG;   // scc後の辺の向きを逆にしたグラフ
  VI vs;      // 帰りがけ順の並び
  VI used;    // すでに調べたか
  VI cmp;     // 属する強連結成分のトポロジカル順
  VVI member; // scc後の同一ノードの集合
  // vector<double> weight;  // i番目の連結成分が持つ情報
  // 初期化
  SCC() { V=K=-1; }
  SCC(int V_): V(V_) {
    G.assign(V_, VI());
    rG.assign(V_, VI());
    used.assign(V_, false);
    cmp.assign(V_, false);
    // weight.assign(V_, 1);
  }
  // 辺を追加
  void add_edge(int from,int to) {
    assert(from<V && to<V);
    G[from].push_back(to);
    rG[to].push_back(from);
  }
  // dfs
  void dfs(int v) {
    used[v]=true;
    for(int nx: G[v]) if(!used[nx]) dfs(nx);
    vs.push_back(v);
  }
  // 逆順dfs
  void rdfs(int v,int k) {
    used[v]=true;
    cmp[v]=k;
    // weight[k] *= p[v];
    for(int nx: rG[v]) if(!used[nx]) rdfs(nx,k);
  }
  // 2回dfsをする O(|V|+|E|)
  int scc() {
    // dfsする
    used.assign(V,0);
    vs.clear();
    for(int v=0;v<V;v++) if(!used[v]) dfs(v);
    // 逆順でdfs
    used.assign(V,0);
    int k=0;
    for(int i=vs.size()-1;i>=0;i--) if(!used[vs[i]]) rdfs(vs[i],k++);
    // i番目の連結成分について
    member.resize(k);
    for(int i=0;i<V;i++) member[cmp[i]].push_back(i);
    // weight.resize(k);
    return K=k;
  }
  // O(ElogE)
  VVI getDAG() {
    assert(K>=0);
    VVI res(K);
    for(int from=0;from<V;from++) {
      for(int to:G[from]) if(cmp[from]!=cmp[to]) res[cmp[from]].push_back(cmp[to]);
    }
    for(int i=0;i<K;i++){
      sort(res[i].begin(),res[i].end());
      res[i].erase(unique(res[i].begin(),res[i].end()),res[i].end());
    }
    return res;
  }
};

signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<string> v(n);
  vector<int> ans(30, 0);
  VVI g(30);
  REP(i, n) {
    string s;
    cin >> s;
    v[i] = s[0];
    v[i] += s.back();
    ans[s.back()-'a'] = 1;
    g[s[0]-'a'].PB(s.back()-'a');
  }

  SCC scc(26);
  VI in(26), out(26);
  REP(i, v.size()) {
    scc.add_edge(v[i][0]-'a', v[i].back()-'a');
    in[v[i].back()-'a']++;
    out[v[i][0]-'a']++;
  }
  scc.scc();
  auto ret = scc.getDAG();

  VI out_s(30);
  REP(i, 26) {
    for(auto j: g[i]) {
      if(scc.cmp[i] != scc.cmp[j]) {
        out_s[i]++;
      }
    }
  }
  // cout << out_s << endl;

  REP(i, 26) {
    if(!ans[i]) continue;
    if(in[i] - out[i] < 0) continue;
    if(out_s[i] != 0) continue;
    cout << (char)(i+'a') << endl;
  }

  // VV<int> g(30);
  // V<int> in(30), out(30);
  // V<int> self(30);
  // REP(i, v.size()) {
  //   if(v[i][0] == v[i].back()) {self[v[i].back()-'a'] = 1; continue;}
  //   g[v[i][0]-'a'].PB(v[i].back()-'a');
  //   out[v[i][0]-'a']++;
  //   in[v[i].back()-'a']++;
  // }

  // V<char> ans;
  // REP(i, 26) {
  //   if(in[i] >= 1 && out[i] == 0) {
  //     ans.PB((char)(i+'a'));
  //   }
  //   else if(out[i] == 0 && self[i]) {
  //     ans.PB((char)(i+'a'));
  //   }
  // }
  // sort(ALL(ans));
  // ans.erase(unique(ALL(ans)), ans.end());
  // for(auto i: ans) cout << i << endl;
  // return 0;

  // bool used[30] = {};
  // function<void(int)> dfs = [&](int num) {
  //   ans.PB((char)(num+'a'));
  //   used[num] = true;
  //   for(auto i: g[num]) {
  //     if(!used[i]) {
  //       dfs(i);
  //     }
  //   }
  // };

  // REP(i, n) {
  //   // 始点をv[i].back()として探索開始してたどり着ける頂点を列挙する
  //   memset(used, false, sizeof(used));
  //   dfs(v[i].back()-'a');

  //   // out[v[i][0]-'a']--;
  //   // in[v[i].back()-'a']--;
  //   // int s = 0, t = 0;
  //   // char c;
  //   // REP(i, 26) {
  //   //   if(in[i] - out[i] == 0) {

  //   //   } else if(in[i] - out[i] == 1) {
  //   //     t++; c = (char)(i + 'a');
  //   //   } else if(in[i] - out[i] == -1) {
  //   //     s++;
  //   //   } else {
  //   //     s = 100;
  //   //     break;
  //   //   }
  //   // }
  //   // if(s == 0 && t == 0) ans.PB(v[i].back());
  //   // else if(s == 1 && t == 1) ans.PB(c);
  //   // cout << i << " " << ans << endl;
  // }

  // sort(ALL(ans));
  // ans.erase(unique(ALL(ans)), ans.end());
  // for(auto i: ans) cout << i << endl;

  return 0;
}

