Motorcycle gear checker! Some of you may be familiar with the way that a motorcycle shifts. But for those who don't, It looks like this

6

5

4

3

2

N

1

Now I want to know what gear I am in after performing a few up and down shifts.
 The program should work from neutral.

Sample input:

V^^


Sample output:

2


As you can see I downshifted once from N to 1 and upshifted twice to 2nd gear.

This is a code golf. Shortest answer in bytes wins.

Note: The input can be any 2 characters. Can be U and D for up and down or whatever you want it has to be a string. You cannot shift beyond 1st or 6th gear. If you are in 6th and upshift again it will stay in 6th. Good luck!
JavaScript (ES6), 49 48 47 46 bytes

Expects:


1 for down
7 for up


f=([c,...s],g=2)=&gt;c?f(s,g-c&amp;7||g):'1N'[--g]||g


Formatted and commented

f = (                   // f is a recursive function which takes:
  [c,                   // - c = next character in input string
      ...s],            // - s = remaining characters
  g = 2                 // - g = current gear, with default = neutral = 2
) =&gt;                    //
  c ?                   // if there's still a character to process:
    f(                  //   do a recursive call with:
      s,                //     - the remaining characters
      g - c &amp; 7 ||      //     - the updated gear if it is valid
      g                 //       or the previous gear if not
    )                   //
  :                     // else:
    '1N'[--g] ||        //   decrement g and output '1' for g = 0, 'N' for g = 1,
    g                   //   or simply the corresponding digit for other values


Gears are mapped as follows:

g MOD 8 = 0 1 2 3 4 5 6 7
          ---------------
gear    = X 1 N 2 3 4 5 6       (where 'X' is an invalid state)


Which allows us to easily check the validity of the current gear with:

(g &amp; 7) != 0


Demo



f=([c,...s],g=2)=&gt;c?f(s,g-c&amp;7||g):'1N'[--g]||g

console.log(f(''))
console.log(f('1'))
console.log(f('11'))
console.log(f('17777'))
console.log(f('1777777771'))