import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
// 注意 hasNext 和 hasNextLine 的区别
Scanner in = new Scanner(System.in);
int stringLength = in.nextInt();
int inputLine = in.nextInt();
String inputStream = in.next();
char[] charArray = new char[stringLength];
int iNodeIndex = -1;
for (int i = 0; i < stringLength; i ++) {
char value = inputStream.charAt(i);
charArray[i] = value;
if (value == 'I') {
iNodeIndex = i;
}
}
int preIndex = iNodeIndex - 1;
int nextIndex = iNodeIndex + 1;
for (int i = 0; i < inputLine; i++) {
String string = in.next();
if (string.equalsIgnoreCase("backspace")) {
if (preIndex == -1) {
continue;
}
char value = charArray[preIndex];
if (value == '(' && nextIndex < stringLength && charArray[nextIndex] == ')') {
preIndex--;
nextIndex++;
} else {
preIndex--;
}
} else if (string.equalsIgnoreCase("delete")) {
if (nextIndex < stringLength) {
nextIndex++;
}
}
}
if (preIndex >= 0) {
for (int i = 0; i <= preIndex; i++) {
System.out.print(charArray[i]);
}
}
System.out.print("I");
if (nextIndex <= stringLength) {
for (int i = nextIndex; i < stringLength; i++) {
System.out.print(charArray[i]);
}
}
}
}