program pil_12_28(input,output);
type
  number = 0..9;
var
  res : number;
    
  function Max(a,b : number) : number;
  begin
    if a>b then Max := a else Max := b;
  end;

  function Min(a,b : number) : number;
  begin
    if a<b then Min := a else Min := b;
  end;

  function readform : number;
  var
    c : char;
    a,b : number;
  begin
    read(c);
    case c of
      '0'..'9' : readform := ord(c)-ord('0');
      'm' : begin
              read(c); {reading '('}
              a := readform;
              read(c); {reading ','}
              b := readform;
              read(c); {reading ')'}
              readform := min(a, b);
            end;
      'M' : begin
              read(c); {reading '('}
              a := readform;
              read(c); {reading ','}
              b := readform;
              read(c); {reading ')'}
              readform := Max(a, b);
            end;
    end;

  end;

begin
  res := readform;
  WriteLn(res);
end.
