This solution came into my mind (but I didn't test it yet).
The first digit is from range 1 to N, thus you can derive from the first digit whether your permutation is in which block of size (N-1)!
2*(2!) + X where X = 0..2!-1
Then you can recursively apply this to the next digits (which is one of (N-1)! permutations).
So with an arbitrary N you can do the following algorithm:
X = 0
while string <> ""
X += ((first digit) - 1) * (N-1)!
decrease all digits in string by 1 which are > first digit
remove first digit from string
N -= 1
return X
In your case:
X = 2
s = "213"
X += (2-1) * 2! => 2
s = "12"
X += (1-1) * 1! => 2
s = "1"
X += (1-1) * 0! => 2
Thus this algorithm is O(N^2).