#include <bits/stdc++.h>
using namespace std;
char buf[50000000];
int up[200000], to[200000];
stack<int> active;
vector<char*> token;
int state;
int that = ~1;
void add(char* l, char* r) {
  *r = 0;
  if (l < r) {
    int x = token.size();
    token.push_back(l);
    up[x] = active.top();
    if (not state) {
      if (l[0] == 't') {
        if (l[1] == 'r')
          active.push(x);
        else
          that = x;
      } else if (l[0] == 'c') {
        to[active.top()] = x, active.pop();
      }
    }
  }
}
int main() {
  int len = fread(buf, 1, sizeof buf, stdin), flip;
  buf[len] = buf[len + 1] = buf[len + 2] = '\n', buf[len + 3] = 0;
  active.push(-1);
  for (char *p = buf, *q = p; *q; ++q) {
    if (*q == '"')
      for (p = ++q; *q != '"' or !(add(p, q), p = q + 1); ++q)
        ;
    else if (!(*q == '_' or *q >= 'a' and *q <= 'z' or *q >= 'A' and *q <= 'Z'))
      flip = (*q == '(' || *q == ')'), add(p, q), p = q + 1, state ^= flip;
  }
  if (~that)
    for (int i = up[that]; ~i; i = up[i]) {
      if (not strcmp(token[to[i] + 1], token[that + 1])) {
        puts(token[to[i] + 2]);
        return 0;
      }
    }
  puts("Unhandled Exception");
}
