pchk=0
gchk=0
win=0
lose=0
for i in `fold -1`
do
	if [ $pchk -lt $gchk ]
	then
		if [ "$i" = "g" ]
		then
			pchk=$((pchk + 1))
			win=$((win + 1))
		else
			pchk=$((pchk + 1))
		fi
	else
		if [ "$i" = "p" ]
		then
			gchk=$((gchk + 1))
			lose=$((lose + 1))
		else
			gchk=$((gchk + 1))
		fi
	fi
done
echo $((win - lose))
