#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
  string line;
  char a='A',b,c,d;
  while (getline(cin, line)){
    stringstream s;
    s << line;
    s >> b >> c >> d;
    if (b == a) a = b;
    if (d == a) a = d;
  }
  cout << a << endl;
}