import java.io.*;
import java.util.*;

import static java.lang.Long.*;

public class RagnarCubicTranscribed {

    private long L;
    private List<Long> a, b;
    private int A, B;
    private long[][][] dp;

    public static void main(String[] args) throws IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            new RagnarCubicTranscribed().run(new Scanner(reader));
        }
    }

    public void run(Scanner sc) throws IOException {
        int n = sc.nextInt();
        L = sc.nextLong();

        a = new ArrayList<>(n);
        b = new ArrayList<>(n);
        a.add(-1L);
        b.add(-1L);
        for (int i = 0; i < n; ++i) {
            String c = sc.next();
            long t = sc.nextLong();
            (c.equals("N") ? a : b).add(t);
        }

        A = a.size();
        B = b.size();
        long INF = 1L << 60;
        dp = new long[2][A + 1][B + 1];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j <= A; j++) {
                Arrays.fill(dp[i][j], INF);
            }
        }
        dp[0][1][0] = 0;
        dp[1][0][1] = 0;

        for (int i = 0; i < A; ++i) {
            for (int j = 0; j < B; ++j) {
                if (i > 0 && dp[0][i][j] < INF) {
                    chain(0, i, j, a.get(i), dp[0][i][j]);
                }
                if (j > 0 && dp[1][i][j] < INF) {
                    chain(1, i, j, b.get(j), dp[1][i][j]);
                }
            }
        }

        System.out.println(min(dp[0][A][B - 1], dp[1][A - 1][B]));
    }

    void chain(int k, int i, int j, long t, long cost) {
        if (k == 0) {
            while (i + 1 < A && a.get(i + 1) <= t) {
                cost += t - a.get(i);
                i += 1;
            }
            if (a.get(i) > t) {
                dp[k][i][j] = min(dp[k][i][j], cost);
                return;
            }
            cost += t - a.get(i);
            dp[k][i + 1][j] = min(dp[k][i + 1][j], cost);
            if (j + 1 < B) {
                chain(1 - k, i, j + 1, t + L, cost);
            }
        } else {
            while (j + 1 < B && b.get(j + 1) <= t) {
                cost += t - b.get(j);
                j += 1;
            }
            if (b.get(j) > t) {
                dp[k][i][j] = min(dp[k][i][j], cost);
                return;
            }
            cost += t - b.get(j);
            dp[k][i][j + 1] = min(dp[k][i][j + 1], cost);
            if (i + 1 < A) {
                chain(1 - k, i + 1, j, t + L, cost);
            }
        }
    }
}
