#include <bits/stdc++.h>
using namespace std;
string getExceptionType(string line, char leftChar, char rightChar) {
  int low = line.find(leftChar) + 1;
  int high = line.find(rightChar, low) - 1;
  while (line[low] == ' ') {
    ++low;
  }
  while (line[high] == ' ') {
    --high;
  }
  return line.substr(low, high - low + 1);
}
int main() {
  int nLines;
  cin >> nLines;
  int nTry = 0;
  int nUseLessTry = 0;
  bool isThrowFind = false;
  string line;
  int pos;
  string expType;
  for (int i = 0; i <= 100000; ++i) {
    getline(cin, line);
    if (line != "") {
      pos = line.find("catch");
      if (pos != -1) {
        if (isThrowFind) {
          if (nUseLessTry > 0) {
            --nUseLessTry;
          } else {
            if (expType == getExceptionType(line, '(', ',')) {
              cout << getExceptionType(line, '"', '"');
              return 0;
            }
          }
        } else {
          --nTry;
        }
      } else {
        pos = line.find("throw");
        if (pos != -1) {
          expType = getExceptionType(line, '(', ')');
          isThrowFind = 1;
        } else {
          if (isThrowFind == 0) {
            ++nTry;
          } else {
            ++nUseLessTry;
          }
        }
      }
    }
  }
  cout << "Unhandled Exception";
  return 0;
}
