#include <bits/stdc++.h>
using namespace std;
map<char, char> m;
char a[200100][2];
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (char i = 'a'; i <= 'z'; i++) m[i] = i;
  for (int i = 0; i < k; i++) {
    cin >> a[i][0] >> a[i][1];
  }
  char ch;
  for (char i = 'a'; i <= 'z'; i++) {
    ch = i;
    for (int j = 0; j < k; j++) {
      if (a[j][0] == ch)
        ch = a[j][1];
      else if (a[j][1] == ch)
        ch = a[j][0];
    }
    m[i] = ch;
  }
  for (int i = 0; i < n; i++) cout << m[s[i]];
}
