const
  deyst = ['+','*','/','-'];

type
    ps  = ^el;
    el  = record
        data : integer;
        prev : ps;
    end;
var
   header : ps;
   polsk  : string;
   this   : string;
   pos1   : byte;
   num1,
   num2   : integer;

Procedure MakeD(var num1:integer;num2:integer;deyst:char);
begin
  case deyst of
    '+': num1 := num1 + num2;
    '-': num1 := num1 - num2;
    '*': num1 := num1 * num2;
    '/': if num2 <> 0 then num1 := num1 div num2;
  end;
end;

Function GetNext(a:string;var pos:byte):string;
var ret : string;
begin
  ret := a[pos];
  inc(pos);
  while (a[pos] <> ',') and (pos1<>length(a)+1) do begin ret := ret + a[pos];inc(pos);end;
  inc(pos);
  GetNext := ret;
end;

Procedure PUSH(i:integer;var head:ps);
var ne : ps;
begin
  New(ne);
  ne^.data := i;
  ne^.prev := head;
  head := ne;
end;

Function POP(var head:ps):integer;
var ret:integer;newhead:ps;
begin
  ret := head^.data;
  newhead := head^.prev;
  Dispose(head);
  head := newhead;
  POP := ret;
end;

begin
 polsk := '8,3,*,5,+,9,+,';
 header^.prev := nil;
 pos1:=1;
 While pos1 <> length(polsk)+1 do
   begin
     this := getNext(polsk,pos1);
     if this[length(this)] in deyst then
       begin
         num1 := POP(header);
         num2 := POP(header);
         makeD(num1,num2,this[1]);
         PUSH(num1,header);
       end
     else
      begin
        val(this,num1,num2);
        PUSH(num1,header);
      end;
   end;
 WriteLN(POP(header));
end.
