// Arup Guha
// 5/11/2016
// Solution to 2016 USACO Bronze January Problem: Angry Cows

import java.util.*;
import java.io.*;

public class mowing {

    final public static int NOSOL = 1000000;
    final public static String DIR = "NWES";
    final public static int[] DX = {-1,0,0,1};
    final public static int[] DY = {0,-1,1,0};

	public static void main(String[] args) throws Exception {

		// Read in data.
		Scanner stdin = new Scanner(new File("mowing.in"));
		int n = stdin.nextInt();

		// Start at 1000,1000 so never go negative.
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();

		// Where we start.
		int x = 1000;
		int y = 1000;
		map.put(5000*x+y, 0);

		int res = NOSOL;
		int t = 0;

		// Process each step.
		for (int i=0; i<n; i++) {

            // Get the direction.
            char curDir = stdin.next().charAt(0);
            int dirNum = 0;
            for (int j=0; j<DIR.length(); j++)
                if (curDir == DIR.charAt(j))
                    dirNum = j;

            // And length.
            int len = stdin.nextInt();

            // Now move.
            for (int j=0; j<len; j++) {
                x = x + DX[dirNum];
                y = y + DY[dirNum];
                t++;
                int code = 5000*x + y;

                // Been here before.
                if (map.containsKey(code)) {
                    int diff = t - map.get(code);
                    res = Math.min(res, diff);
                    map.put(code, t);
                }

                else
                    map.put(code, t);
            }
		}

		// Update if there's no solution.
		if (res == NOSOL) res = -1;

		// Write result.
		PrintWriter out = new PrintWriter(new FileWriter("mowing.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}
