#!/usr/bin/perl -w

use v5.36;
use strict;

$_ = <>;
my @moves = /(\S)/g;

my @units = (
	[ [0, 0], [1, 0], [2, 0], [3, 0] ], # horiz i
	[ [0, 1], [1, 1], [2, 1], [1, 0], [1, 2] ], # x
	[ [0, 0], [1, 0], [2, 0], [2, 1], [2, 2] ], # v
	[ [0, 0], [0, 1], [0, 2], [0, 3] ], # vert i
	[ [0, 0], [0, 1], [1, 0], [1, 1] ], # o
);

my @map;
my $w = 7;
my $h = 0;

my $units = 0;
my $move = 0;

sub can_move($unit, $vect) {
	# say "can_move $vect->[0] $vect->[1]";
	for my $pt (@$unit) {
		my @dst = ($pt->[0] + $vect->[0], $pt->[1] + $vect->[1]);
		return 0 if $dst[0] < 0 || $dst[0] >= $w;
		return 0 if $dst[1] < 0;
		return 0 if $map[$dst[1]][$dst[0]];
	}
	return 1;
}

sub dump_map {
	for my $y (reverse 0 .. $h) {
		for my $x (0 .. $w-1) {
			print $map[$y][$x] ? '#' : ' ';
		}
		print "\n";
	}
	say "---- $h ----";
}

while ($units < 2022) {
	my $u = $units[$units % @units];
	my ($x, $y) = (2, $h+3);
	while (1) {	
		my $m = $moves[$move++];
		$move = 0 if $move > $#moves;
		if ($m eq '>') {
			$x++ if can_move($u, [$x+1, $y]);
		} else {
			$x-- if can_move($u, [$x-1, $y]);
		}
		if (can_move($u, [$x, $y-1])) {
			$y--;
			next;
		}
		last;
	}
	for my $pt (@$u) {
		$map[$y + $pt->[1]][$x + $pt->[0]] = 1;
		$h = 1 + $y + $pt->[1] if $h < 1 + $y + $pt->[1];
	}
	# dump_map();
	$units++;
}

say $h;
