#!/usr/bin/perl

use v5.30;
use strict;

my ($x, $y) = (0, 0);

my @path = split /[,\s]/, <>;

#   |/
#   o
#  /|
# x y

sub dist {
	my ($x,$y) = @_;
	my $dist;
	if ($x >= 0 && $y >= 0 || $x <= 0 && $y <= 0) {
		$dist = abs($x + $y);
	} elsif (abs($x) >= abs($y)) {
		$dist = abs($x);
	} else {
		$dist = abs($y);
	}
	return $dist;
}

my $max;
for my $dir (@path) {
	if ($dir eq 's') {
		$y--;
	} elsif ($dir eq 'n') {
		$y++;
	} elsif ($dir eq 'ne') {
		$x++;
	} elsif ($dir eq 'nw') {
		$x--;
		$y++;
	} elsif ($dir eq 'se') {
		$x++;
		$y--;
	} elsif ($dir eq 'sw') {
		$x--;
	}
	my $d = dist($x,$y);
	$max = $d if !$max || $max < $d;
}

say $max;
	

