#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9 + 7);
int main() {
  int n, m;
  cin >> n >> m;
  char s[n];
  map<char, char> newLetter;
  for (int i = 0; i < int(n); ++i) {
    cin >> s[i];
  }
  vector<pair<char, char> > op;
  while (m--) {
    char a, b;
    cin >> a >> b;
    if (a == b) continue;
    op.push_back(make_pair(a, b));
  }
  char tmp;
  for (char c = 'a'; c <= 'z'; c++) {
    tmp = c;
    for (int i = 0; i < int(op.size()); ++i) {
      char a = op[i].first, b = op[i].second;
      if (tmp == a)
        tmp = b;
      else if (tmp == b)
        tmp = a;
    }
    newLetter[c] = tmp;
  }
  for (int i = 0; i < int(n); ++i) {
    cout << newLetter[s[i]];
  }
  return 0;
}
