```
'I':1,
'V':5,
'X':10,
'L':50,
'C':100,
'D':500,
'M':1000
}
s = s[::-1]
num = 0
for i in range(len(s)):
if i == 0:
num = N[s[i]]
elif N[s[i]] < N[s[i-1]]:
num = num - N[s[i]]
else:
num += N[s[i]]
return num
```