#include using namespace std; int main() { int i; int N; int iCnt; ios::sync_with_stdio( false ); cin.tie( 0 ); cin >> N; vector p( N ); vector A( N ); iota( A.begin(), A.end(), 1 ); for( i = 0; i < N; i++ ) cin >> p[ i ]; iCnt = 0; do { iCnt++; if( A == p ) break; } while( next_permutation( A.begin(), A.end() ) ); cout << iCnt << endl; return 0; }