function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var P = parseInt(input[1].split(" ").join(""));
  var Q = parseInt(input[2].split(" ").join(""));
  (function() {
    var generatePermutation = function(perm, pre, post, n) {
      var elem, i, rest, len;
      if (n > 0)
        for (i = 0, len = post.length; i < len; ++i) {
          rest = post.slice(0);
          elem = rest.splice(i, 1);
          generatePermutation(perm, pre.concat(elem), rest, n - 1);
        }
      else
        perm.push(pre);
    };
  
    /*
    extend Array.prototype
    e.g. [0, 1, 2].permutation(2)
    => [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]
    */
    Array.prototype.permutation = function(n) {
      if (n == null) n = this.length;
      var perm = [];
      generatePermutation(perm, [], this, n);
      return perm;
    };
  })();
  var x = new Array(N);
  for(var i =0;i<N;i++){
    x[i]=i+1;
  }
  var y = x.permutation();
  y=y.map(i => parseInt(i.join("")));
  y.sort(function(a,b){return a-b});
  var pp;
  var qq;
  for(var i =0;i<y.length;i++){
    if(y[i]==P){
      pp=i;
    }
    if(y[i]==Q){
      qq=i;
    }
    if(pp!=undefined&&qq!=undefined){
      var ans = Math.abs(pp-qq);
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));