#!/usr/bin/env python3
deg = {"N": 0, "E": 90, "S": 180, "W": 270, "NE": 45, "SE": 135, "SW": 225, "NW": 315}


def degrees(d):
    if d in deg:
        return deg[d]
    ans = deg[d[-2:]]
    EW = d[-1]
    NS = d[-2]
    precision = 22.5
    for w in reversed(d[:-2]):
        if EW == "E":
            if NS == "N":
                if w == "N":
                    ans -= precision
                elif w == "E":
                    ans += precision
            elif NS == "S":
                if w == "E":
                    ans -= precision
                elif w == "S":
                    ans += precision
        elif EW == "W":
            if NS == "N":
                if w == "N":
                    ans += precision
                elif w == "W":
                    ans -= precision
            elif NS == "S":
                if w == "W":
                    ans += precision
                elif w == "S":
                    ans -= precision
        precision /= 2

    return ans


X, Y = input().strip().split()
print(min((degrees(X) - degrees(Y) + 360) % 360, (degrees(Y) - degrees(X) + 360) % 360))
