#include <bits/stdc++.h>
using namespace std;
template <class T>
T _abs(T n) {
  return (n < 0 ? -n : n);
}
template <class T>
T _max(T a, T b) {
  return (!(a < b) ? a : b);
}
template <class T>
T _min(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
T sq(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
bool inside(T a, T b, T c) {
  return a <= b && b <= c;
}
template <class T>
void setmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
const int INF = 0x7f7f7f7f;
int main() {
  int n, found, first, i, d;
  int v1, v2, z;
  string str, throw_exp, catch_exp, catch_msg;
  cin >> n;
  getchar();
  first = z = 0;
  stack<int> s;
  while (getline(cin, str)) {
    ++z;
    if ((found = str.find("throw")) != string::npos && !first) {
      i = found + 5;
      first = z;
      while (!isalpha(str[i++]))
        ;
      --i;
      throw_exp.clear();
      for (; isalpha(str[i]); i++) {
        throw_exp.push_back(str[i]);
      }
      throw_exp.push_back('\0');
    } else if ((found = str.find("catch")) != string::npos) {
      i = found + 5;
      while (!isalpha(str[i++]))
        ;
      --i;
      catch_exp.clear();
      for (; isalpha(str[i]); i++) {
        catch_exp.push_back(str[i]);
      }
      catch_exp.push_back('\0');
      if (throw_exp.compare(catch_exp) == 0 && s.top() < first) {
        catch_msg.clear();
        while (!isalnum(str[i++]))
          ;
        --i;
        for (; str[i] != '"'; i++) {
          catch_msg.push_back(str[i]);
        }
        string second(catch_msg);
        cout << second << endl;
        return 0;
      }
      s.pop();
    } else if ((found = str.find("try")) != string::npos) {
      s.push(z);
    }
  }
  cout << "Unhandled Exception\n";
  return 0;
}
