#include <bits/stdc++.h>
using namespace std;
int n, cnt;
string t;
string s;
inline bool is_good(char c, int p) {
  if (p == 1 && c == ' ') return true;
  if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
      (c >= '0' && c <= '9'))
    return true;
  return false;
}
inline string STR(int &cur, string p, bool qw) {
  string ret = "";
  while (!is_good(s[cur], 0)) cur++;
  while (is_good(s[cur], 1)) ret += s[cur++];
  if (qw == false)
    for (int i = ret.size() - 1; i >= 0; --i)
      if (ret[i] == ' ')
        ret.erase(ret.size() - 1);
      else
        break;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  bool flag = false, pq = true;
  cin >> n;
  getline(cin, s);
  for (int qw = 0; qw < n; ++qw) {
    cerr << qw << endl;
    pq = true;
    int cur = 0;
    getline(cin, s);
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] != ' ') break;
      if (i == s.size() - 1) pq = false;
    }
    if (pq == false) continue;
    string h = STR(cur, s, 0);
    if (h == "try") {
      if (flag) cnt++;
    } else if (h == "throw") {
      t = STR(cur, s, 0);
      flag = true;
    } else if (h == "catch") {
      if (flag) {
        if (cnt > 0)
          cnt--;
        else {
          h = STR(cur, s, 0);
          if (h == t) {
            cout << STR(cur, s, 1) << endl;
            return 0;
          }
        }
      }
    } else
      ;
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
