/***
** AUTHOR::ASHUTOSH MOUDGIL
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define M 998244353
int tree[1501]={INT_MAX};
vi target(501,INT_MAX);
int dp[501][501];
map<int,int> clr;
void build(int s,int e, int i){
if(s==e){
tree[i] = target[s];
return ;
}
int mid = (s+e)/2;
build(s,mid,2*i);
build(mid+1,e,2*i+1);
tree[i] = min(tree[2*i],tree[2*i+1]);
return ;
}
int query(int s, int e, int l , int r,int i){
if( l > e || r < s )
return INT_MAX;
if(l<=s && r>=e){
return tree[i];
}
int mid = (s+e)/2;
return min(query(s,mid,l,r,2*i),query(mid+1,e,l,r,2*i+1));
}
int solve(int l,int r,int n){
if(l <0 || r>=n)
return 0;
if(l==r)
return 1;
if(l>r)
return 0;
if(dp[l][r]!=-1)
return dp[l][r];
int cmin = query(0,n-1,l,r,1);
int ci = clr[cmin];
//cout << "ci,l,r:"<<ci<<" "<<l<<" "<<r<<endl;
int ans = 0,left=0,right=0;
for(int a = l;a<=ci;a++){
left += dp[l][a-1]*dp[a][ci-1];
}
for(int b = ci;b<=r;b++){
right += dp[ci+1][b]*dp[b+1][r];
}
dp[l][r]=left*right;
return dp[l][r];
}
void mymain(){
int n,m;
cin>>n>>m;
//vi target(n);
for(int i=0;i<n;i++){
cin>>target[i];
clr[target[i]]=i;
}
build(0,n-1,1);
for(int i=0;i<501;i++)
for(int j=0;j<501;j++)
dp[i][j]=-1;
cout << solve( 0,n-1,n )<<endl;
}
signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t;
t=1;
//cin>>t;
for(int tt=0;tt<t;tt++){
//cout << "Case #" << tt+1 <<": ";
mymain();
}
return 0;
}
Lyo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nQgcixpbnQgaSl7CiAgICBpZiggbCA+IGUgfHwgciA8IHMgKQogICAgICAgIHJldHVybiBJTlRfTUFYOwogICAgaWYobDw9cyAmJiByPj1lKXsKICAgICAgICByZXR1cm4gdHJlZVtpXTsKICAgIH0KICAgIGludCBtaWQgPSAocytlKS8yOwogICAgcmV0dXJuIG1pbihxdWVyeShzLG1pZCxsLHIsMippKSxxdWVyeShtaWQrMSxlLGwsciwyKmkrMSkpOwoKfQoKaW50IHNvbHZlKGludCBsLGludCByLGludCBuKXsKCiAgICBpZihsIDwwIHx8IHI+PW4pCiAgICAgICAgcmV0dXJuIDA7CiAgICBpZihsPT1yKQogICAgICAgIHJldHVybiAxOwogICAgaWYobD5yKQogICAgICAgIHJldHVybiAwOwoKICAgIGlmKGRwW2xdW3JdIT0tMSkKICAgICAgICByZXR1cm4gZHBbbF1bcl07CgogICAgaW50IGNtaW4gPSBxdWVyeSgwLG4tMSxsLHIsMSk7CiAgICBpbnQgY2kgPSBjbHJbY21pbl07CiAgICAvL2NvdXQgPDwgImNpLGwscjoiPDxjaTw8IiAiPDxsPDwiICI8PHI8PGVuZGw7CiAgICBpbnQgYW5zID0gMCxsZWZ0PTAscmlnaHQ9MDsKCiAgICBmb3IoaW50IGEgPSBsO2E8PWNpO2ErKyl7CgogICAgICAgIGxlZnQgKz0gZHBbbF1bYS0xXSpkcFthXVtjaS0xXTsKICAgIH0KICAgIGZvcihpbnQgYiA9IGNpO2I8PXI7YisrKXsKCiAgICAgICAgcmlnaHQgKz0gZHBbY2krMV1bYl0qZHBbYisxXVtyXTsKICAgIH0KCiAgICAgICAgZHBbbF1bcl09bGVmdCpyaWdodDsKCgogICAgcmV0dXJuIGRwW2xdW3JdOwoKfQoKCgoKdm9pZCBteW1haW4oKXsKaW50IG4sbTsKY2luPj5uPj5tOwoKICAvL3ZpIHRhcmdldChuKTsKICBmb3IoaW50IGk9MDtpPG47aSsrKXsKICAgIGNpbj4+dGFyZ2V0W2ldOwogICAgY2xyW3Rh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