#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1011

DO dp[NN][NN];

int a[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, m;

	cin >> n >> m;

	for(int i=1; i<=n; i++) gn(a[i]);

	for(int i=1; i<=n; i++) {

		for(int j=i+1; j<=n; j++) {

			dp[i][j] = (a[i] > a[j]);

		}

	}

	while(m--) {

		int u, v; gn(u, v);

		if(u > v) swap(u, v);

		for(int i=1; i<u; i++) {

			dp[i][u] = dp[i][v] = (dp[i][u] + dp[i][v])/2;

		}

		for(int i=u+1; i<v; i++) {

			DO tmp = dp[u][i];

			dp[u][i] = (dp[u][i] + 1 - dp[i][v]) / 2;

			dp[i][v] = (dp[i][v] + 1 - tmp) / 2;

		}

		for(int i=v+1; i<=n; i++) dp[u][i] = dp[v][i] = (dp[u][i] + dp[v][i]) / 2;

		dp[u][v] = 0.5;

	}

	DO ans=0;

	for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++) ans += dp[i][j];

	printf("%.9lf\n", ans);

	return 0;

}


#include <cstdio>

using namespace std;

#define rep(i, m) for(int i = 0; i < (int)m; ++i)

int n, m;
int a[1010];
double ret;
double p[1010][1010];

int main(){
    scanf("%d %d", &n, &m);
    rep(i, n) scanf("%d", &a[i]);
    rep(i, n) rep(j, n) if(i != j) p[i][j] = (a[i] > a[j] ? 1.0 : 0.0);
    while(m--){
	int a, b; scanf("%d %d", &a, &b); --a; --b;
	p[a][b] = p[b][a] = 0.5;
	rep(i, n) if(i != a && i != b){
	    p[i][a] = p[i][b] = (p[i][a] + p[i][b]) / 2.0;
	    p[a][i] = p[b][i] = 1.0 - p[i][a];
	}
    }
    rep(i, n) rep(j, i) ret += p[j][i];
    printf("%.8lf\n", ret);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int SIZEN=1010;
int N,M;
int d[SIZEN];
double p[SIZEN][SIZEN];
void work(void){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(d[i]>d[j]) p[i][j]=1;
		}
	}
	int a,b;
	for(int i=0;i<M;i++){
		scanf("%d%d",&a,&b);
		a--,b--;
		for(int j=0;j<N;j++){
			if(j==a||j==b) continue;
			p[a][j]=p[b][j]=(p[a][j]+p[b][j])/2;
			p[j][a]=1-p[a][j];
			p[j][b]=1-p[b][j];
		}
		p[a][b]=p[b][a]=0.5;
	}
	double ans=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			ans+=p[i][j];
		}
	}
	printf("%.10lf\n",ans);
}
void read(void){
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++) scanf("%d",&d[i]);
}
int main(){
	read();
	work();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int SIZEN=1010;
int N,M;
int d[SIZEN];
double p[SIZEN][SIZEN];
void work(void){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(d[i]>d[j]) p[i][j]=1;
		}
	}
	int a,b;
	for(int i=0;i<M;i++){
		scanf("%d%d",&a,&b);
		a--,b--;
		for(int j=0;j<N;j++){
			if(j==a||j==b) continue;
			p[a][j]=p[b][j]=(p[a][b]+p[b][j])/2;
			p[j][a]=1-p[a][j];
			p[j][b]=1-p[b][j];
		}
		p[a][b]=p[b][a]=0.5;
	}
	double ans=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			ans+=p[i][j];
		}
	}
	printf("%.10lf\n",ans);
}
void read(void){
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++) scanf("%d",&d[i]);
}
int main(){
	read();
	work();
	return 0;
}


/*===============*\
|  ID: TMANDZU    |
|    LANG: C++    |
\*===============*/
//Tornike Mandzulashvili
//#pragma comment(linker,"/STACK:256000000")
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <set>

#define EPS 0.000000001
#define Pi 3.14159265
#define hash1 1000003
#define hash2 1000033
#define md 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define S size()
#define MX(aa,bb) (aa>bb?aa:bb)
#define MN(aa,bb) (aa<bb?aa:bb)
#define fi first
#define se second
#define PI pair < int,int >
#define REP(i,a,n) for(i=a;i<n;i++)
#define sc scanf
#define pt printf

using namespace std;

int i,j,n,m,a,b;
int p[1005];
double dp[1005][1005];
double ans=0.0;
double A[1005][1005];

main()
{
 //   freopen("text.in","r",stdin);
 //   freopen("text.out","w",stdout);

    cin>>n>>m;
    for (i=1;i<=n;i++)
        cin>>p[i];
    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
        if (p[i]>p[j]) dp[i][j]=1.0;

    while (m--)
    {
        cin>>a>>b;

        for (i=1;i<=n;i++)
        {
            A[i][a]=dp[i][a];
            A[i][b]=dp[i][b];
            dp[i][a]=0;
            dp[i][b]=0;
        }

        for (i=1;i<=n;i++)
        if (i!=a && i!=b)
        {
            dp[i][a]=0.5*A[i][a]+0.5*A[i][b];
            dp[i][b]=0.5*A[i][a]+0.5*A[i][b];
            dp[a][i]=1-dp[i][a];
            dp[b][i]=1-dp[i][b];
        }

        dp[a][b]=dp[b][a]=0.5;
    }

    for (i=1;i<=n;i++)
    for (j=i+1;j<=n;j++)
    ans+=dp[i][j];

    printf("%.9lf\n",ans);

}


/*===============*\
|  ID: TMANDZU    |
|    LANG: C++    |
\*===============*/
//Tornike Mandzulashvili
//#pragma comment(linker,"/STACK:256000000")
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <set>

#define EPS 0.000000001
#define Pi 3.14159265
#define hash1 1000003
#define hash2 1000033
#define md 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define S size()
#define MX(aa,bb) (aa>bb?aa:bb)
#define MN(aa,bb) (aa<bb?aa:bb)
#define fi first
#define se second
#define PI pair < int,int >
#define REP(i,a,n) for(i=a;i<n;i++)
#define sc scanf
#define pt printf

using namespace std;

int i,j,n,m,a,b;
int p[1005];
double dp[1005][1005];
double ans=0.0;

main()
{
  //  freopen("text.in","r",stdin);
  //  freopen("text.out","w",stdout);

    scanf("%d %d",&n,&m);
    for (i=1;i<=n;i++)
        scanf("%d",&p[i]);

    for (i=1;i<=n;i++)
    for (j=1;j<=n;j++)
    if (p[i]>p[j]) dp[i][j]=1.0;

    for (i=1;i<=m;i++)
    {
         scanf("%d %d",&a,&b);

         dp[a][b]=0.5;

         for (j=1;j<=n;j++)
         {
             if (j==a || j==b) continue;
             dp[a][j]=dp[b][j]=0*5+dp[a][j]+0.5*dp[b][j];
         }
    }

    for (i=1;i<=n;i++)
    for (j=i+1;j<=n;j++)
    ans+=dp[i][j];

    printf("%.9lf\n",ans);

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#define LL long long
const double pi=acos(-1.0),e=exp(1.0);
using namespace std;
#define MAX 1100
int a[MAX],i,j,N,M,x,y;
double f[MAX][MAX],ans;

int main(){
    cin >> N >> M;
    for (i=1;i<=N;i++) cin >> a[i];
    for (i=1;i<=N;i++)
        for (j=1;j<=N;j++)
            f[i][j]=a[i]>a[j];
    while (M--){
        cin >> x >> y;
        f[x][y]=f[y][x]=0.5;
        for (i=1;i<=N;i++)
            if (i!=x && i!=y){
                f[i][x]=f[i][y]=(f[i][y]+f[i][x])*0.5;
                f[x][i]=f[y][i]=(f[x][i]+f[y][i])*0.5;
            }
    }
    for (i=1;i<=N;i++)
        for (j=i+1;j<=N;j++)
            ans+=f[i][j];
    cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#define LL long long
const double pi=acos(-1.0),e=exp(1.0);
using namespace std;
#define MAX 1100
int a[MAX],i,j,N,M,x,y;
double f[MAX][MAX],ans;

int main(){
    cin >> N >> M;
    for (i=1;i<=N;i++) cin >> a[i];
    for (i=1;i<=N;i++)
        for (j=1;j<=N;j++)
            f[i][j]=a[i]>a[j];
    while (M--){
        cin >> x >> y;
        f[x][y]=f[y][x]=0.5;
        for (i=1;i<=N;i++)
            if (i!=x && i!=y){
                f[i][x]=f[i][y]=(f[i][y]+f[i][x])*0.5;
                f[x][i]=f[y][i]=1-f[i][x];
            }
    }
    for (i=1;i<=N;i++)
        for (j=i+1;j<=N;j++)
            ans+=f[i][j];
    printf("%.10lf\n",ans);
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#define LL long long
const double pi=acos(-1.0),e=exp(1.0);
using namespace std;
#define MAX 1100
int a[MAX],i,j,N,M,x,y;
double f[MAX][MAX],ans;

int main(){
    cin >> N >> M;
    for (i=1;i<=N;i++) cin >> a[i];
    for (i=1;i<=N;i++)
        for (j=1;j<=N;j++)
            f[i][j]=a[i]>a[j];
    while (M--){
        cin >> x >> y;
        f[x][y]=f[y][x]=0.5;
        for (i=1;i<=N;i++)
            if (i!=x && i!=y){
                f[i][x]=f[i][y]=(f[i][y]+f[i][x])*0.5;
                f[x][i]=f[y][i]=(f[x][i]+f[y][i])*0.5;
            }
    }
    for (i=1;i<=N;i++)
        for (j=i+1;j<=N;j++)
            ans+=f[i][j];
    printf("%.10lf\n",ans);
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <string>
#include <queue>
#include <vector>

using namespace std;

int n, m;
int p[1010];
double pd[1010][1010];
int a[1010], b[1010];

int main() {

  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    for (int j = 0; j < n; j++) {
      pd[i][j] = 0;
    }
  }

  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i], &b[i]);
    a[i]--;
    b[i]--;
    if (a[i] > b[i]) swap(a[i],b[i]);
  }

  for (int i = m-1; i >= 0; i--) {
    for (int j = a[i] + 1; j < b[i]; j++) {
      pd[j][b[i]] = 0.5*pd[j][b[i]] + 0.5*(1 - pd[a[i]][j]);
    }
    for (int j = a[i] + 1; j < b[i]; j++) {
      pd[a[i]][j] = 0.5*pd[a[i]][j] + 0.5*(1 - pd[b[i]][j]);
    }
    for (int j = a[i]+1; j < b[i]; j++) {
      pd[j][a[i]] = pd[a[i]][j];
      pd[b[i]][j] = pd[j][b[i]];
    }
    pd[a[i]][b[i]] = pd[b[i]][a[i]] = 0.5;
  }

  double res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (p[i] < p[j]) {
        res += pd[i][j];
      } else {
        res += (1.0 - pd[i][j]);
      }
    }
  }
  printf("%.10lf\n", res);

  return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 1000 + 5;

int n, m;
int an[N];
double pnn[N][N];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d", &an[i]);
	for(int i = 1; i <= n; ++i) for(int j = i + 1; j <= n; ++j) pnn[i][j] = (an[i] > an[j]);
	while(m--) {
		int a, b; scanf("%d%d", &a, &b);
		if(a > b) swap(a, b);
		pnn[a][b] = 0.5;
		for(int i = 1; i < a; ++i) pnn[i][a] = pnn[i][b] = 0.5 * (pnn[i][a] + pnn[i][b]);
		for(int i = a + 1; i < b; ++i) {
			double pa = pnn[a][i], pb = pnn[i][b];
			pnn[a][i] = 0.5 * (pa + 1. - pb);
			pnn[i][b] = 0.5 * (1. - pa + pb);
		}
	}
	double ans = 0.;
	for(int i = 1; i <= n; ++i) for(int j = i + 1; j <= n; ++j) ans += pnn[i][j];
	printf("%.10f\n", ans);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 1000 + 5;

int n, m;
int an[N];
double pnn[N][N];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d", &an[i]);
	for(int i = 1; i <= n; ++i) for(int j = i + 1; j <= n; ++j) pnn[i][j] = (an[i] > an[j]);
	while(m--) {
		int a, b; scanf("%d%d", &a, &b);
		if(a > b) swap(a, b);
		pnn[a][b] = 0.5;
		for(int i = 1; i < a; ++i) pnn[i][a] = pnn[i][b] = 0.5 * (pnn[i][a] + pnn[i][b]);
		for(int i = a + 1; i < b; ++i) {
			double pa = pnn[a][i], pb = pnn[i][b];
			pnn[a][i] = 0.5 * (pa + 1. - pb);
			pnn[i][b] = 0.5 * (1. - pa + pb);
		}
		for(int i = b + 1; i <= n; ++i) pnn[a][i] = pnn[b][i] = 0.5 * (pnn[a][i] + pnn[b][i]);
	}
	double ans = 0.;
	for(int i = 1; i <= n; ++i) for(int j = i + 1; j <= n; ++j) ans += pnn[i][j];
	printf("%.10f\n", ans);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>

using namespace std;

double p[1010][1010];
int a[1010];
int n,m;

int main()
{
	freopen("inversion.in","r",stdin);
	freopen("inversion.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=n;j++)
	    if (a[i]>a[j]) p[i][j]=1; else p[i][j]=0;
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		for (int j=1;j<=n;j++)
		{
			if (j==x || j==y) continue;
			double t=0.5*(p[j][x]+p[j][y]);
			p[j][x]=t;p[j][y]=t;
			t=0.5*(p[x][j]+p[y][j]);
			p[x][j]=t;p[y][j]=t;
		}
		p[x][y]=0.5;p[y][x]=0.5;
	}
	double ans=0;
	for (int i=1;i<=n;i++)
	  for (int j=i+1;j<=n;j++)
	    ans+=p[i][j];
	printf("%.6lf\n",ans);
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>

using namespace std;

double p[1010][1010];
int a[1010];
int n,m;

int main()
{
	//freopen("inversion.in","r",stdin);
	//freopen("inversion.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=n;j++)
	    if (a[i]>a[j]) p[i][j]=1; else p[i][j]=0;
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		for (int j=1;j<=n;j++)
		{
			if (j==x || j==y) continue;
			double t=0.5*(p[j][x]+p[j][y]);
			p[j][x]=t;p[j][y]=t;
			t=0.5*(p[x][j]+p[y][j]);
			p[x][j]=t;p[y][j]=t;
		}
		p[x][y]=0.5;p[y][x]=0.5;
	}
	double ans=0;
	for (int i=1;i<=n;i++)
	  for (int j=i+1;j<=n;j++)
	    ans+=p[i][j];
	printf("%.7lf\n",ans);
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,s,t)for (int i=s;i<=t;i++)
#define NN 1010
using namespace std;
long double f[NN][NN],ans;
int n,m,a[NN];
int main()
{
//  freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
    scanf("%d%d\n",&n,&m);
    rep(i,1,n)
        scanf("%d",&a[i]);
    rep(i,1,n)
        rep(j,i+1,n)
            if(a[i]>a[j])f[i][j]=1.0;
    long double t,t1,t2;
    int x,y;
    rep(T,1,m)
    {
        scanf("%d%d",&x,&y);
        if(x==y)continue;
        if(x>y)swap(x,y);
        f[x][y]=0.5;
        rep(i,1,x-1)
            t=(f[i][x]+f[i][y])*0.5,f[i][y]=f[i][x]=t;
        rep(i,x+1,y-1)
        {
            t1=(f[x][i]+1-f[i][y])*0.5;
            t2=(1-f[x][i]+f[i][y])*0.5;
            f[x][i]=t1,f[i][y]=t2;
        }
        rep(i,y+1,n)
            t=(f[x][i]+f[y][i])*0.5,f[x][i]=f[y][i]=t;
    }
    ans=0.0;
    rep(i,1,n)
        rep(j,i+1,n)
            ans+=f[i][j];
    printf("%.9lf",(double)ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,s,t)for (int i=s;i<=t;i++)
#define lc(x) son[x][0]
#define rc(x) son[x][1]
#define esp 1e-10
#define M 550
#define NN 1010
using namespace std;
long double f[NN][NN],ans;
int n,m,a[NN];
int main()
{
//  freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
    scanf("%d%d\n",&n,&m);
    rep(i,1,n)
        scanf("%d",&a[i]);
    rep(i,1,n)
        rep(j,i+1,n)
            if(a[i]>a[j])f[i][j]=1.0;
    long double t,t1,t2;
    int x,y;
    rep(T,1,m)
    {
        scanf("%d%d",&x,&y);
        if(x==y)continue;
        if(x>y)swap(x,y);
        f[x][y]=0.5;
        rep(i,1,x-1)
            t=(f[i][x]+f[i][y])*0.5,f[i][y]=f[i][x]=t;
        rep(i,x+1,y-1)
        {
            t1=(f[x][i]+1-f[i][y])*0.5;
            t2=(1-f[x][i]+f[i][y])*0.5;
            f[x][i]=t1,f[i][y]=t2;
        }
        rep(i,y+1,n)
            t=(f[x][i]+f[y][i])*0.5,f[x][i]=f[y][i]=t;
    }
    ans=0.0;
    rep(i,1,n)
        rep(j,i+1,n)
            ans+=f[i][j];
    printf("%.9Lf",ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 1010;

int n, m, a[MAXN];
double prob[MAXN][MAXN];

int main ()
{
    scanf ("%d%d", &n, &m);

    for (int i = 0; i < n; ++i) scanf ("%d", a + i);

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) prob[i][j] = a[i] > a[j];

    for (int i = 0; i < m; ++i) {
        int a, b; scanf ("%d%d", &a, &b);
        --a; --b;
        if (a > b) swap (a, b);
        for (int j = 0; j < n; ++j) {
            if (j == a || j == b) continue;
            prob[a][j] = prob[b][j] = (prob[a][j] + prob[b][j]) / 2.0;
            prob[j][a] = prob[j][b] = (prob[j][a] + prob[j][b]) / 2.0;
        }
        prob[a][b] = prob[b][a] = .5;
    }

    double rez = 0.0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j) rez += prob[j][i];

    printf ("%lf\n", rez);

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 1010;

int n, m, a[MAXN];
double prob[MAXN][MAXN];

int main ()
{
    scanf ("%d%d", &n, &m);

    for (int i = 0; i < n; ++i) scanf ("%d", a + i);

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) prob[i][j] = a[i] > a[j];

    for (int i = 0; i < m; ++i) {
        int a, b; scanf ("%d%d", &a, &b);
        --a; --b;
        if (a > b) swap (a, b);
        for (int j = 0; j < n; ++j) {
            if (j == a || j == b) continue;
            prob[a][j] = prob[b][j] = (prob[a][j] + prob[b][j]) / 2.0;
            prob[j][a] = prob[j][b] = (prob[j][a] + prob[j][b]) / 2.0;
        }
        prob[a][b] = prob[b][a] = (prob[a][b] + prob[b][a]) / 2.0;
    }

    double rez = 0.0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j) rez += prob[j][i];

    printf ("%lf\n", rez);

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 1010;

int n, m, a[MAXN];
double prob[MAXN][MAXN];

int main ()
{
    scanf ("%d%d", &n, &m);

    for (int i = 0; i < n; ++i) scanf ("%d", a + i);

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) prob[i][j] = a[i] > a[j];

    for (int i = 0; i < m; ++i) {
        int a, b; scanf ("%d%d", &a, &b);
        --a; --b;
        if (a > b) swap (a, b);
        for (int j = 0; j < n; ++j) {
            if (j == a || j == b) continue;
            prob[a][j] = prob[b][j] = .5;
            prob[j][a] = prob[j][b] = .5;
        }
        prob[a][b] = prob[b][a] = .5;
    }

    double rez = 0.0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j) rez += prob[j][i];

    printf ("%lf\n", rez);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <cctype>
#define maxn 1005

using namespace std;

int n,m,a[maxn];
double p[maxn][maxn],ans;

void init()
 {
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;i++)scanf("%d",&a[i]);
 }

void work()
 {
  int i,j,k,x,y;
  for (i=1;i<n;i++)
   for (j=i+1;j<=n;j++)if (a[i]>a[j])p[j][i]=1;else p[i][j]=1;
  while (m--)
   {
    scanf("%d%d",&x,&y);
    p[x][y]=p[y][x]=0.5;
    for (i=x+1;i<y;i++)
     {
      p[x][i]=p[y][i]=(p[x][i]+p[y][i])*0.5;p[i][x]=p[i][y]=(p[i][x]+p[i][y])*0.5;
     }
   }
  for (i=1;i<n;i++)
   for (j=i+1;j<=n;j++)ans+=p[i][j];
  printf("%.9lf",ans);
 }

int main()
 {
  init();
  work();
  return 0;
 }


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <cctype>
#define maxn 1005

using namespace std;

int n,m,a[maxn];
double p[maxn][maxn],ans=0;

void init()
 {
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;i++)scanf("%d",&a[i]);
 }

void work()
 {
  int i,j,k,x,y;
  for (i=1;i<n;i++)
   for (j=i+1;j<=n;j++)if (a[i]>a[j])p[i][j]=1;else p[j][i]=1;
  while (m--)
   {
    scanf("%d%d",&x,&y);
    p[x][y]=p[y][x]=0.5;
    for (i=1;i<=n;i++)if (i!=x && i!=y)
     {
      p[x][i]=p[y][i]=(p[x][i]+p[y][i])*0.5;p[i][x]=p[i][y]=(p[i][x]+p[i][y])*0.5;
     }
   }
  for (i=1;i<n;i++)
   for (j=i+1;j<=n;j++)ans+=p[i][j];
  printf("%.9lf",ans);
 }

int main()
 {
  init();
  work();
  return 0;
 }


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <cctype>
#define maxn 1005

using namespace std;

int n,m,a[maxn];
double p[maxn][maxn],ans;

void init()
 {
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;i++)scanf("%d",&a[i]);
 }

void work()
 {
  int i,j,k,x,y;
  for (i=1;i<n;i++)
   for (j=i+1;j<=n;j++)if (a[i]>a[j])ans=ans+1;
    else p[i][j]=1;
  while (m--)
   {
    scanf("%d%d",&x,&y);if (y<x)swap(x,y);
    ans+=p[x][y]-0.5;
    for (i=x+1;i<y;i++)ans+=p[x][i]-0.5+p[i][y]-0.5;
    for (i=x+1;i<y;i++)p[x][i]=p[i][y]=(p[x][i]+p[i][y])*0.5;
    p[x][y]=0.5;
   }
  printf("%.9lf",ans);
 }

int main()
 {
  init();
  work();
  return 0;
 }


#include<iostream>
#include<iomanip>
#include<cstdio>
using namespace std;

const int N = 1100;

int n, m, x[N];
double f[N][N], rez;

int main() {
	int i, j, a, b;

	freopen("test", "r", stdin);

	cin >> n >> m;

	for(i = 1; i<=n; ++i)
		cin >> x[i];

	for(i = 1; i<=n; ++i)
		for(j = 1; j<=n; ++j) if(i != j)
			f[i][j] = (x[i] > x[j] ? 1 : 0);

	for(i = 1; i<=m; ++i) {
		cin >> a >> b;

		f[a][b] = f[b][a] = 0.5;

		for(j = 1; j<=n; ++j) if(j != a && j != b) {
			f[j][a] = f[j][b] = f[j][a]/2 + f[j][b]/2;
			f[a][j] = f[b][j] = 1 - f[j][a];
		}
	}
	for(i = 1; i!=n; ++i)
		for(j = i + 1; j<=n; ++j)
			rez += f[i][j];
	cout << setprecision(7) << fixed << rez;

	return 0;
}


#include<iostream>
#include<iomanip>
#include<cstdio>
using namespace std;

const int N = 1100;

int n, m, x[N];
double f[N][N], rez;

int main() {
	int i, j, a, b;

	//freopen("test", "r", stdin);

	cin >> n >> m;

	for(i = 1; i<=n; ++i)
		cin >> x[i];

	for(i = 1; i<=n; ++i)
		for(j = 1; j<=n; ++j) if(i != j)
			f[i][j] = (x[i] > x[j] ? 1 : 0);

	for(i = 1; i<=m; ++i) {
		cin >> a >> b;

		f[a][b] = f[b][a] = 0.5;

		for(j = 1; j<=n; ++j) if(j != a && j != b) {
			f[j][a] = f[j][b] = f[j][a]/2 + f[j][b]/2;
			f[a][j] = f[b][j] = 1 - f[j][a];
		}
	}
	for(i = 1; i!=n; ++i)
		for(j = i + 1; j<=n; ++j)
			rez += f[i][j];
	cout << setprecision(7) << fixed << rez;

	return 0;
}


#include<cstdio>
#define MAXN 1010
double dp[MAXN][MAXN];
int a[MAXN];
int main()
{
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
		scanf("%d",a+i);
	for(int i=0;i<N;i++)
		for(int j=0;j<i;j++)
			if(a[i]>a[j])
				dp[j][i]=1.0;
	double qx[MAXN];
	double qy[MAXN];
	for(int i=0;i<M;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--; y--;
		if(x>y)
		{
			int tmp=x;
			x=y;
			y=tmp;
		}
		for(int j=0;j<x;j++)
			qx[j]=(dp[x][j]+dp[x][y])/2;
		for(int j=y+1;j<N;j++)
			qx[j]=(dp[j][x]+dp[j][y])/2;
		for(int j=x+1;j<y;j++)
			//xj invers per = (1+xj-yj)/2
			//jy invers per = (1+xj-yj)/2
			qx[j]=(1+dp[x][j]-dp[j][y])/2;
		for(int j=0;j<x;j++)
			dp[x][j]=dp[y][j]=qx[j];
		for(int j=y+1;j<N;j++)
			dp[j][x]=dp[j][y]=qx[j];
		for(int j=x+1;j<y;j++)
		{
			dp[x][j]=qx[j];
			dp[j][y]=1-qx[j];
		}
		dp[x][y]=0.5;
	}
	double res=0;
	for(int i=0;i<N;i++)
		for(int j=0;j<i;j++)
			res+=dp[j][i];
	printf("%.12lf",res);
}


#include<cstdio>
#define MAXN 1010
double dp[MAXN][MAXN];
int a[MAXN];
int main()
{
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
		scanf("%d",a+i);
	for(int i=0;i<N;i++)
		for(int j=0;j<i;j++)
			if(a[i]<a[j])
				dp[j][i]=1.0;
	double qx[MAXN];
	double qy[MAXN];
	for(int i=0;i<M;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--; y--;
		if(x>y)
		{
			int tmp=x;
			x=y;
			y=tmp;
		}
		for(int j=0;j<x;j++)
			qx[j]=(dp[j][x]+dp[j][y])/2;
		for(int j=y+1;j<N;j++)
			qx[j]=(dp[x][j]+dp[y][j])/2;
		for(int j=x+1;j<y;j++)
			//xj invers per = (1+xj-yj)/2
			//jy invers per = (1+xj-yj)/2
			qx[j]=(1+dp[x][j]-dp[j][y])/2;
		for(int j=0;j<x;j++)
			dp[j][x]=dp[j][y]=qx[j];
		for(int j=y+1;j<N;j++)
			dp[x][j]=dp[y][j]=qx[j];
		for(int j=x+1;j<y;j++)
		{
			dp[x][j]=qx[j];
			dp[j][y]=1-qx[j];
		}
		dp[x][y]=0.5;
	}
	double res=0;
	for(int i=0;i<N;i++)
		for(int j=0;j<i;j++)
			res+=dp[j][i];
	printf("%.12lf",res);
}


#include<cstdio>
#define MAXN 1010
double dp[MAXN][MAXN];
int a[MAXN];
int main()
{
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
		scanf("%d",a+i);
	for(int i=0;i<N;i++)
		for(int j=0;j<i;j++)
			if(a[i]<a[j])
				dp[j][i]=1.0;
	double qx[MAXN];
	double qy[MAXN];
	for(int i=0;i<M;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--; y--;
		if(x>y)
		{
			int tmp=x;
			x=y;
			y=tmp;
		}
		for(int j=0;j<x;j++)
			qx[j]=(dp[x][j]+dp[x][y])/2;
		for(int j=y+1;j<N;j++)
			qx[j]=(dp[j][x]+dp[j][y])/2;
		for(int j=x+1;j<y;j++)
			//xj invers per = (1+xj-yj)/2
			//jy invers per = (1+xj-yj)/2
			qx[j]=(1+dp[x][j]-dp[j][y])/2;
		for(int j=0;j<x;j++)
			dp[x][j]=dp[y][j]=qx[j];
		for(int j=y+1;j<N;j++)
			dp[j][x]=dp[j][y]=qx[j];
		for(int j=x+1;j<y;j++)
		{
			dp[x][j]=qx[j];
			dp[j][y]=1-qx[j];
		}
		dp[x][y]=0.5;
	}
	double res=0;
	for(int i=0;i<N;i++)
		for(int j=0;j<i;j++)
			res+=dp[j][i];
	printf("%.12lf",res);
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 200005

#define pr16

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}

#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define tr(c,it)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    ain(a,n);
    double f[n][n];
    MEM(f,0);
    rep(i,n)
      rep(j,i)
        f[i][j] = (a[i] < a[j]);

    int l,s;
    rep(it,m)
    {
      cin>>s>>l;
      s--;l--;
      if(s>l)
        swap(s,l);
      f[l][s] = .5;
      loop(i,s+1,l)
      {
        //pr2(it,i);
        double tmp = f[i][s];
        f[i][s] = .5*(1-f[l][i]+f[i][s]);
        f[l][i] = .5*(1-tmp+f[l][i]);
      }
      rep(i,s)
        f[s][i] = f[l][i] = (f[s][i] + f[l][i])/2;
      loop(i,l+1,n)
        f[i][s] = f[i][l] = (f[i][s] + f[i][l])/2;

  //  prdd(f,n,n);
    }
    double ans = 0;
    rep(i,n)
      rep(j,i)
        ans += f[i][j];
    printf("%.9lf\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 200005

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    ain(a,n);
    double f[n][n];
    MEM(f,0);
    rep(i,n)
      rep(j,i)
        f[i][j] = (a[i] < a[j]);

    int l,s;
    rep(i,m)
    {
      cin>>s>>l;
      s--;l--;
      if(s>l)
        swap(s,l);
      f[l][s] = .5;
      loop(i,s+1,l)
      {
        f[l][i] = f[i][s] = .5;
      }
    }

    double ans = 0;
    rep(i,n)
      rep(j,i)
        ans += f[i][j];
    printf("%.9lf\n",ans);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
double prob[1002][1002];
int n,m,l,r,s[1002],p[1002];
int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&s[i]);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(s[i]<s[j]) prob[i][j]=0;
            else prob[i][j]=1;
        }
    }
    for(int i=1;i<=m;i++){
        scanf("%d %d",&l,&r);
        if(l>r) swap(l,r);
        for(int j=1;j<l;j++){
            double temp=0.5*(prob[j][l]+prob[j][r]);
            prob[j][l]=prob[j][r]=temp;
        }
        for(int j=r+1;j<=n;j++){
            double temp=0.5*(prob[l][j]+prob[r][j]);
            prob[l][j]=prob[r][j]=temp;
        }
        for(int j=l+1;j<r;j++){
            double temp=prob[l][j];
            prob[l][j]=0.5*(prob[l][j]+1-prob[j][r]);
            prob[j][r]=0.5*(prob[j][r]+1-temp);
        }
        prob[l][r]=0.5;
    }
    double ans=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++) ans+=prob[i][j];
    }
    printf("%.10lf\n",ans);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
double prob[1002][1002];
int n,m,l,r,s[1002],p[1002];
int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&s[i]);
        p[s[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(p[i]<p[j]) prob[i][j]=0;
            else prob[i][j]=1;
        }
    }
    for(int i=1;i<=m;i++){
        scanf("%d %d",&l,&r);
        if(l>r) swap(l,r);
        for(int j=1;j<l;j++){
            double temp=0.5*(prob[j][l]+prob[j][r]);
            prob[j][l]=prob[j][r]=temp;
        }
        for(int j=r+1;j<=n;j++){
            double temp=0.5*(prob[l][j]+prob[r][j]);
            prob[l][j]=prob[r][j]=temp;
        }
        for(int j=l+1;j<r;j++){
            double temp=prob[l][j];
            prob[l][j]=0.5*(prob[l][j]+1-prob[j][r]);
            prob[j][r]=0.5*(prob[j][r]+1-temp);
        }
        prob[l][r]=0.5;
    }
    double ans=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++) ans+=prob[i][j];
    }
    printf("%.10lf\n",ans);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define N 1010
using namespace std;

int n, m, a[N];
double tbl[N][N], tmp[N][N];

int main (){
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            tbl[i][j] = (a[i] > a[j]);
    while(m--){
        int x, y; scanf("%d%d", &x, &y); --x, --y;
        for(int i = 0; i < n; i++){
            tbl[x][i] = tbl[y][i] = (tbl[x][i]+tbl[y][i])/2;
            tbl[i][x] = tbl[i][y] = (tbl[i][x]+tbl[i][y])/2;
        }
        tbl[x][x] = tbl[y][y] = 0;
        tbl[x][y] = 0.5, tbl[y][x] = 0.5;
    }
    double ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = i+1; j < n; j++)
            ans += tbl[i][j];
    printf("%.10lf\n", ans);
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

const int MAXN = 100010 ;
const int N = 100000 ;
const int MOD = 1000000007 ;

int f[MAXN] , sum[MAXN] , a[MAXN] ;
int n , Div[MAXN] ;

int power(int x,int y){
    int ret=1;
    while (y){
        if (y&1) ret=(long long)ret*x%MOD;
        x=(long long)x*x%MOD;
        y>>=1;
    }
    return ret;
}

int main(){
    scanf("%d",&n);
    memset(f,0,sizeof(f));memset(sum,0,sizeof(sum));
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        f[a[i]]++ ;
    }
    sum[0]=0;
    for (int i=1;i<MAXN;i++)
        sum[i]=sum[i-1]+f[i];
    long long ans=1;
    for (int i=2;i<=N;i++){
        int cnt=0;
        for (int j=1;j*j<=i;j++)
            if (i%j==0){
                Div[cnt++]=j;
                if (j*j!=i)
                    Div[cnt++]=i/j;
            }
        long long tmp=1;
        sort(Div,Div+cnt);
        for (int j=0;j<cnt;j++){
            if (Div[j]==i){
                int s = sum[MAXN-1]-sum[Div[j]-1];
                int fn = j+1;
                int cur = (power(fn,s)-power(fn-1,s)+MOD)%MOD;
                tmp = tmp * cur % MOD ;
            }else{
                int s = sum[Div[j+1]-1]-sum[Div[j]-1];
                int fn = j+1;
                int cur = power(fn,s);
                tmp = tmp * cur % MOD;
            }
        }
        ans = ans + tmp ;
        if (ans >= MOD) ans -= MOD ;
    }
    cout<< (ans % MOD + MOD) % MOD << endl ;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (root+root)
#define sag (root+root+1)
#define orta ((bas+son)/2)
#define ll long long
#define pii pair<int,int>
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

const int N=1e3+5;
const int mod=1e9+7;
const int inf=1e9+7;

int i,m,x,y,j,k,l,n,tme;
int A[N];

double ans;

vector<pii > V[N],V2[N][N];

vector<double> dp[N][N];

double f(int x,int y,int k){
	if(k==V2[x][y].size()){
		if(A[x]<A[y])
			return 1;
		return 0;
	}
	double &r=dp[x][y][k];
	if(r!=-1)
		return r;
	r=0;
	if(V2[x][y][k].st==x){
		if(V2[x][y][k].nd<y)
			r+=f(x,y,k+1)/2.0;
		else
			r+=f(y,x,k+1)/2.0;
	}
	else {
		if(V2[x][y][k].nd>x)
			r+=f(x,y,k+1)/2.0;
		else r+=f(y,x,k+1)/2.0;
	}
	r+=f(x,y,k+1)/2.0;
	return r;
}

main(){

	scanf("%d %d",&n,&m);

	for(i=1 ; i<=n ; i++)
		scanf("%d",A+i);

	for(i=1 ; i<=m ; i++){
		scanf("%d %d",&x,&y);
		V[x].pb(mp(i,y));
		V[y].pb(mp(i,x));
	}

	for(i=1 ; i<=n ; i++)
		for(j=i+1 ; j<=n ; j++){
			l=0;
			tme=0;
			for(k=0 ; k<V[i].size() ; k++){
				while(l<V[j].size() and V[j][l].st<V[i][k].st){
					if(V[j][l].nd==i and !tme)
						tme=V[j][l].st;
					else
						V2[i][j].pb(mp(j,V[j][l].nd));
					l++;
				}
				if(V[i][k].nd==i and !tme)
					tme=V[i][k].st;
				else
					V2[i][j].pb(mp(i,V[i][k].nd));
			}
			while(l<V[j].size()){
				if(V[j][l].nd==i and !tme)
					tme=V[j][l].st;
				else
					V2[i][j].pb(mp(j,V[j][l].nd));
				l++;
			}
			if(tme)
				V2[i][j].pb(mp(i,j));
			V2[j][i]=V2[i][j];
			dp[i][j].resize(V2[i][j].size(),-1);
			dp[j][i].resize(V2[i][j].size(),-1);
		}

	for(i=1 ; i<=n ; i++)
		for(j=i+1 ; j<=n ; j++)
			ans+=f(i,j,0);

	printf("%.8lf",ans);
}


#include<bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (root+root)
#define sag (root+root+1)
#define orta ((bas+son)/2)
#define ll long long
#define pii pair<int,int>
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

const int N=1e3+5;
const int mod=1e9+7;
const int inf=1e9+7;

int i,m,x,y,j,k,l,n,tme;
int A[N];

double ans;

pii e[N];

vector<int > V[N][N];

vector<double> dp[N][N];

double f(int x,int y,int k){
	if(k==V[x][y].size())
		return x<y;
	if(x>y)
		return 1.0-f(y,x,k);
	double &r=dp[x][y][k];
	if(r>=0)
		return r;
	int ind=V[x][y][k];
	r=f(x,y,k+1)/2.0;
	if(e[ind].nd==x)
		x=e[ind].st;
	else if(e[ind].st==x)
		x=e[ind].nd;
	if(e[ind].nd==y)
		y=e[ind].st;
	else if(e[ind].st==y)
		y=e[ind].nd;
	int t=lower_bound(V[x][y].begin(),V[x][y].end(),ind+1)-V[x][y].begin();
	return r+=f(x,y,t)/2.0;
}

main(){

	scanf("%d %d",&n,&m);

	for(i=1 ; i<=n ; i++)
		scanf("%d",A+i);

	for(i=1 ; i<=m ; i++){
		scanf("%d %d",&x,&y);
		e[i]=mp(x,y);
		for(j=1 ; j<=n ; j++)
			V[x][j].pb(i),V[j][x].pb(i);
		for(j=1 ; j<=n ; j++)
			V[y][j].pb(i),V[j][y].pb(i);
	}

	for(i=1 ; i<=n ; i++)
		for(j=1 ; j<=n ; j++){
			V[i][j].resize(unique(V[i][j].begin(),V[i][j].end())-V[i][j].begin());
			dp[i][j].resize(V[i][j].size(),-1);
		}

	for(i=1 ; i<=n ; i++)
		for(j=i+1 ; j<=n ; j++)
			if(A[i]<A[j])
				ans+=f(j,i,0);
			else ans+=1-f(j,i,0);

	printf("%.8lf",ans);
}


# include <iostream>
# include <cstdio>
using namespace std;
int n,m,x,y,a[1001];
double F[1001][1001],ans;
void Mix(double &a, double &b)
{
	a=b=(a+b)/2;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			F[i][j]=a[i]>a[j],F[j][i]=1-F[i][j];
	for(int i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		Mix(F[x][y],F[y][x]);
		for(int i=0;i<n;i++)
			if(i-x&&i-y)Mix(F[i][x],F[i][y]),Mix(F[x][i],F[y][i]);
	}
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=F[i][j];
	printf("%.8lf",ans);
}


# include <iostream>
# include <cstdio>
using namespace std;
int n,m,x,y,a[1001];
double F[1001][1001],ans;
void Mix(double &a, double &b)
{
	a=b=(a+b)/2;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			F[i][j]=a[i]>a[j],F[j][i]=1-F[i][j];
	for(int i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		Mix(F[x][y],F[y][x]);
		for(int i=1;i<=n;i++)
			if(i-x&&i-y)Mix(F[i][x],F[i][y]),Mix(F[x][i],F[y][i]);
	}
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=F[i][j];
	printf("%.8lf",ans);
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 100005;
inline int read ()
{
	int res, ok = 1;
	char ch;
	for (ch = getchar (); ch < '0' || ch > '9'; ch = getchar ())
	if (ch == '-')
	ok = -1;
	res = ch - '0';
	for (ch = getchar (); ch >= '0' && ch <= '9'; ch = getchar ())
	res = res * 10 + ch - '0';
	return res * ok;
}
int n, m, a[1005];
double f[1005][1005], ans;
/*struct bign
{
	int len, s[1005];
	void clear()
	{
		len = 1;
		memset (s, 0, sizeof (s));
	}
	bign operator + (const bign& b) const
	{
		bign c;
		c.clear();
		c.len = max (len, b.len);
		for (int i = 1; i <= c.len; i++)
		c.s[i] = s[i] + b.s[i];
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	bign operator + (const int& b) const
	{
		bign c;
		c.clear();
		c.len = len;
		for (int i = 1; i <= len; i++)
		c.s[i] = s[i];
		c.s[1] += b;
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	bign operator * (const bign b) const
	{
		bign c;
		c.clear();
		c.len = len + b.len - 1;
		for (int i = 1; i < len; i++)
		for (int j = 1; j <= b.len; j++)
		c.s[i + j - 1] += s[i] * b.s[j];
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	bign operator * (const int& b) const
	{
		bign c;
		c.clear();
		c.len = len;
		for (int i = 1; i <= len; i++)
		c.s[i] = s[i] * b;
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	void print ()
	{
		printf ("%d", s[len]);
		for (int i = len - 1; i >= 1; i--)
		printf ("%04d", s[i]);
		printf ("\n");
	}
};
inline void solve ()
{
	bign a, b;
	int lena, lenb;
	char s[1005], t[1005];
	a.clear();
	b.clear();
	scanf ("%s", s + 1);
	scanf ("%s", t + 1);
	lena = strlen (s + 1);
	lenb = strlen (t + 1);
	for (int i = 1; i <= lena; i++)
	{
		a = a * 10;
		a = a + (s[i] - '0');
	}
	for (int i = 1; i <= lenb; i++)
	{
		b = b * 10;
		b = b + (s[i] - '0');
	}
	a.print();
	b.print();
}*/
int main ()
{
	n = read();
	m = read();
	for (int i = 1; i <= n; i++)
	a[i] = read();
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++)
	if (i != j)
	f[i][j] = a[i] > a[j] ? 1.0 : 0.0;
	while (m--)
	{
		int x, y;
		x = read();
		y = read();
		f[x][y] = f[y][x] = 0.5;
		for (int i = 1; i <= n; i++)
		if (i != x && i != y)
		{
			f[i][x] = f[i][y] = (f[i][x] + f[i][y]) * 0.5;
			f[x][i] = f[y][i] = 1 - f[i][x];
		}
	}
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++)
	ans += f[i][j];
	printf ("%lf\n", ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 100005;
inline int read ()
{
	int res, ok = 1;
	char ch;
	for (ch = getchar (); ch < '0' || ch > '9'; ch = getchar ())
	if (ch == '-')
	ok = -1;
	res = ch - '0';
	for (ch = getchar (); ch >= '0' && ch <= '9'; ch = getchar ())
	res = res * 10 + ch - '0';
	return res * ok;
}
int n, m, a[1005];
double f[1005][1005], ans;
/*struct bign
{
	int len, s[1005];
	void clear()
	{
		len = 1;
		memset (s, 0, sizeof (s));
	}
	bign operator + (const bign& b) const
	{
		bign c;
		c.clear();
		c.len = max (len, b.len);
		for (int i = 1; i <= c.len; i++)
		c.s[i] = s[i] + b.s[i];
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	bign operator + (const int& b) const
	{
		bign c;
		c.clear();
		c.len = len;
		for (int i = 1; i <= len; i++)
		c.s[i] = s[i];
		c.s[1] += b;
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	bign operator * (const bign b) const
	{
		bign c;
		c.clear();
		c.len = len + b.len - 1;
		for (int i = 1; i < len; i++)
		for (int j = 1; j <= b.len; j++)
		c.s[i + j - 1] += s[i] * b.s[j];
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	bign operator * (const int& b) const
	{
		bign c;
		c.clear();
		c.len = len;
		for (int i = 1; i <= len; i++)
		c.s[i] = s[i] * b;
		for (int i = 1; i < c.len; i++)
		{
			c.s[i + 1] += c.s[i] / 10000;
			c.s[i] %= 10000;
		}
		while (c.s[c.len] >= 10000)
		{
			c.s[c.len + 1] = c.s[c.len] / 10000;
			c.s[c.len] %= 10000;
			c.len++;
		}
		return c;
	}
	void print ()
	{
		printf ("%d", s[len]);
		for (int i = len - 1; i >= 1; i--)
		printf ("%04d", s[i]);
		printf ("\n");
	}
};
inline void solve ()
{
	bign a, b;
	int lena, lenb;
	char s[1005], t[1005];
	a.clear();
	b.clear();
	scanf ("%s", s + 1);
	scanf ("%s", t + 1);
	lena = strlen (s + 1);
	lenb = strlen (t + 1);
	for (int i = 1; i <= lena; i++)
	{
		a = a * 10;
		a = a + (s[i] - '0');
	}
	for (int i = 1; i <= lenb; i++)
	{
		b = b * 10;
		b = b + (s[i] - '0');
	}
	a.print();
	b.print();
}*/
int main ()
{
	n = read();
	m = read();
	for (int i = 1; i <= n; i++)
	a[i] = read();
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++)
	if (i != j)
	f[i][j] = a[i] > a[j] ? 1.0 : 0.0;
	while (m--)
	{
		int x, y;
		x = read();
		y = read();
		f[x][y] = f[x][y] = 0.5;
		for (int i = 1; i <= n; i++)
		if (i != x && i != y)
		{
			f[i][x] = f[i][y] = (f[i][x] + f[i][y]) * 0.5;
			f[x][i] = f[y][i] = 1 - f[i][x];
		}
	}
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++)
	ans += f[i][j];
	printf ("%lf\n", ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1010

int n, m;
int a[N];
double f[N][N], g[N];

int main() {
	//freopen("in.txt", "r", stdin);
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++) scanf("%d", a + i);
    for(int i = 1; i <= n; i ++) {
    	for(int j = 1; j <= n; j ++) {
    		if(a[i] > a[j]) f[i][j] = 1.;
			else f[i][j] = 0.;
    	}
    }
    for(int i = 1, x, y; i <= m; i ++) {
    	scanf("%d%d", &x, &y);
		for(int j = 1; j <= n; j ++) {
			if(j == x) g[j] = 0.;
			else if(j == y) g[j] = 0.5; else g[j] = (f[y][j] + f[x][j]) * 0.5;
		}
		for(int j = 1; j <= n; j ++) {
			f[y][j] = f[x][j] = g[j];
			f[j][y] = f[j][x] = 1. - g[j];
		}
    }
    double ans = 0.;
    for(int i = 1; i < n; i ++) for(int j = i + 1; j <= n; j ++) ans += f[i][j];
    printf("%.12lf\n", ans);
	return 0;
}


//codeforces 258D Little Elephant and Broken Sorting
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=1005;
int n,m;
int a[mxn];
double dp[mxn][mxn];
int main()
{
	double ans=0;
	int i,j,u,v;
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n)
	  fo(j,i+1,n)
	    if(a[i]>a[j]) dp[i][j]=1,dp[j][i]=0;
	    else dp[i][j]=0,dp[j][i]=1;
	while(m--)
	{
		scanf("%d%d",&u,&v);
		dp[u][v]=dp[v][u]=0.5;
		fo(i,1,n) if(i!=u && i!=v)
		  dp[u][i]=dp[v][i]=0.5*(dp[u][i]+dp[v][i]),
		  dp[i][u]=dp[i][v]=0.5*(dp[i][u]+dp[i][v]);
	}
	fo(i,1,n) fo(j,i+1,n) ans+=dp[i][j];
	printf("%.9lf\n",ans);
	return 0;
}


//codeforces 258D Little Elephant and Broken Sorting
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=1005;
int n,m;
int a[mxn];
double dp[mxn][mxn];
int main()
{
	double ans;
	int i,j,u,v;
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n)
	  fo(j,i+1,n)
	    if(a[i]>a[j]) dp[i][j]=1,dp[j][i]=0;
	    else dp[i][j]=0,dp[j][i]=1;
	while(m--)
	{
		scanf("%d%d",&u,&v);
		dp[u][v]=dp[v][u]=0.5;
		fo(i,1,n) if(i!=u && i!=v)
		  dp[u][i]=dp[v][i]=0.5*(dp[u][i]+dp[v][i]),
		  dp[i][u]=dp[i][v]=0.5*(dp[i][u]+dp[i][v]);
	}
	fo(i,1,n) fo(j,i+1,n) ans+=dp[i][j];
	printf("%.9f\n",ans);
	return 0;
}


//codeforces 258D Little Elephant and Broken Sorting
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=1005;
int n,m;
int a[mxn];
double dp[mxn][mxn];
int main()
{
	double ans;
	int i,j,u,v;
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n)
	  fo(j,i+1,n)
	    if(a[i]>a[j]) dp[i][j]=1,dp[j][i]=0;
	    else dp[i][j]=0,dp[j][i]=1;
	while(m--)
	{
		scanf("%d%d",&u,&v);
		dp[u][v]=dp[v][u]=0.5;
		fo(i,1,n) if(i!=u && i!=v)
		  dp[u][i]=dp[v][i]=0.5*(dp[u][i]+dp[v][i]),
		  dp[i][u]=dp[i][v]=0.5*(dp[i][u]+dp[i][v]);
	}
	fo(i,1,n) fo(j,i+1,n) ans+=dp[i][j];
	printf("%.9lf\n",ans);
	return 0;
}


#include <iostream>
#include <vector>

#define MAX_N 1050

double Ac[MAX_N][MAX_N], DP[MAX_N][MAX_N];
int N, M;
using namespace std;
vector<int> A(MAX_N, 0);
vector<double> P[MAX_N];

void move(int a, int b)
{
    vector<double> va = P[a];
    vector<double> vb = P[b];

    for(int i = 1; i <= N; i++)
    {
        P[a][i] /= 2;
        P[b][i] /= 2;
    }

    for(int i = 1; i <= N; i++)
    {
        P[a][i] += vb[i] / 2;
        P[b][i] += va[i] / 2;
    }
}

void in()
{
    cin >> N >> M;

    for(int i = 0; i <= N; i++)
        for(int n = 0; n <= N; n++)
            P[i].push_back(0);

    for(int i = 1; i <= N; i++)
    {
        cin >> A[i];
        P[i][A[i]] = 1;
    }

    for(int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        move(a,b);
    }

    // Cumulative

    for(int i = 1; i <= N; i++)
        for(int k = N; k >= 1; k--)
            Ac[i][k] = P[i][k] + Ac[i][k + 1];
}

void solve()
{
    double total = 0;

    for(int i = 1; i <= N; i++)
        for(int k = N; k >= 1; k--)
            for(int p = i - 1; p >= 1; p--)
            {
                double rem = 1 - P[p][k];
                total += P[i][k] * (Ac[p][k + 1] / rem);
            }

    cout << total << "\n";
}

int main()
{
    in();
    solve();

    return 0;
}


#include <iostream>
#include <vector>

#define MAX_N 1050

double P[MAX_N][MAX_N];
int N, M;
using namespace std;
vector<int> A(MAX_N, 0);

void move(int a, int b)
{
    for(int i = 1; i <= N; i++)
        if(i != a && i != b)
        {
            P[i][a] = P[i][b] = 0.5*(P[i][a] + P[i][b]);
            P[a][i] = P[b][i] = 0.5*(P[a][i] + P[b][i]);
        }

    P[a][b] = P[b][a] = 0.5;
}

void in()
{
    cin >> N >> M;

    for(int i = 1; i <= N; i++)
        cin >> A[i];

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= N; j++)
            P[i][j] = A[i] > A[j] ? 1 : 0;

    for(int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        move(a,b);
    }
}

void solve()
{
    double total = 0;

    for(int i = 1; i <= N; i++)
        for(int j = i + 1; j <= N; j++)
            total += P[i][j];

    cout << total << "\n";
}

int main()
{
    in();
    solve();

    return 0;
}


#include <iomanip>
#include <iostream>
#include <vector>

#define MAX_N 1050

double P[MAX_N][MAX_N];
int N, M;
using namespace std;
vector<int> A(MAX_N, 0);

void move(int a, int b)
{
    for(int i = 1; i <= N; i++)
        if(i != a && i != b)
        {
            P[i][a] = P[i][b] = 0.5*(P[i][a] + P[i][b]);
            P[a][i] = P[b][i] = 0.5*(P[a][i] + P[b][i]);
        }

    P[a][b] = P[b][a] = 0.5;
}

void in()
{
    cin >> N >> M;

    for(int i = 1; i <= N; i++)
        cin >> A[i];

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= N; j++)
            P[i][j] = A[i] > A[j] ? 1 : 0;

    for(int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        move(a,b);
    }
}

void solve()
{
    double total = 0;

    for(int i = 1; i <= N; i++)
        for(int j = i + 1; j <= N; j++)
            total += P[i][j];

    cout << setprecision(16) << total << "\n";
}

int main()
{
    in();
    solve();

    return 0;
}


#include<iostream>
#include<cstdio>
#include<memory.h>
#include<string>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#define ll long long
#define ii pair<int,int>
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define rep(x,y,z) for (int x=y;x<z;x++)
#define repe(x,y,z) for (int x=y;x<=z;x++)
#define all(x) x.begin(),x.end()
#define X first
#define Y second
using namespace std;
const int size=110000,mod=1000000007 ,inf=0x3f3f3f3f;
const double pi=acos(-1.0);
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int nex[2][4]={0,1,0,-1,1,0,-1,0};
/**************************************/
int n,m;
int ar[1100];
double dp[1100][1100];
ii op[1100];
int main ()
{
	cin>>n>>m;
	rep(i,1,n+1)
		cin>>ar[i];
	rep(j,0,m)
		cin>>op[j].first>>op[j].second;
	rep(i,1,n+1)
		rep(j,1,n+1)
			dp[i][j]=ar[i]>ar[j];
	rep(i,0,m)
	{
		int x=op[i].first,y=op[i].second;
		rep(j,1,n+1)
			if (j!=x&&j!=y)
			{
				dp[j][y]=dp[j][x]=(dp[j][x]+dp[j][y])/2;
				dp[x][j]=1-dp[j][x];
				dp[y][j]=1-dp[j][y];
			}
		dp[x][y]=dp[y][x]=0.5;
	}
	double ans=0;
	rep(i,1,n+1)
		rep(j,i+1,n+1)
			ans+=dp[i][j];
	printf("%.10lf\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<memory.h>
#include<string>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#define ll long long
#define ii pair<int,int>
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define rep(x,y,z) for (int x=y;x<z;x++)
#define repe(x,y,z) for (int x=y;x<=z;x++)
#define all(x) x.begin(),x.end()
#define X first
#define Y second
using namespace std;
const int size=110000,mod=1000000007 ,inf=0x3f3f3f3f;
const double pi=acos(-1.0);
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int nex[2][4]={0,1,0,-1,1,0,-1,0};
/**************************************/
int n,m;
int ar[1100];
double dp[1100][1100];
ii op[1100];
int main ()
{
	cin>>n>>m;
	rep(i,1,n+1)
		cin>>ar[i];
	rep(j,0,m)
		cin>>op[j].first>>op[j].second;
	rep(i,1,n+1)
		rep(j,1,n+1)
			dp[i][j]=ar[i]>ar[j];
	rep(i,0,m)
	{
		int x=op[i].first,y=op[i].second;
		rep(j,1,n+1)
			if (j!=x&&j!=y)
			{
				dp[j][y]=dp[j][x]=(dp[j][x]+dp[j][y])/2;
				dp[x][j]=1-dp[j][x];
				dp[y][j]=1-dp[j][y];
			}
		dp[x][y]=dp[y][x]=0.5;
	}
	double ans=0;
	rep(i,1,n+1)
		rep(j,i+1,n+1)
			ans+=dp[i][j];
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<memory.h>
#include<string>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#define ll long long
#define ii pair<int,int>
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define rep(x,y,z) for (int x=y;x<z;x++)
#define repe(x,y,z) for (int x=y;x<=z;x++)
#define all(x) x.begin(),x.end()
#define X first
#define Y second
using namespace std;
const int size=110000,mod=1000000007 ,inf=0x3f3f3f3f;
const double pi=acos(-1.0);
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int nex[2][4]={0,1,0,-1,1,0,-1,0};
/**************************************/
int n,m;
int ar[1100];
double dp[1100][1100];
ii op[1100];
int main ()
{
	cin>>n>>m;
	rep(i,1,n+1)
		cin>>ar[i];
	rep(j,0,m)
		cin>>op[j].first>>op[j].second;
	rep(i,1,n+1)
		rep(j,1,n+1)
			dp[i][j]=ar[i]>ar[j];
	rep(i,0,m)
	{
		int x=op[i].first,y=op[i].second;
		rep(j,1,n+1)
			if (j!=x&&j!=y)
			{
				dp[j][y]=dp[j][x]=(dp[j][x]+dp[j][y])/2;
				dp[x][j]=1-dp[j][x];
				dp[y][j]=1-dp[j][y];
			}
		dp[x][y]=dp[y][x]=0.5;
	}
	double ans=0;
	rep(i,1,n+1)
		rep(j,i+1,n+1)
			ans+=dp[i][j];
	printf("%lf\n",ans);
	return 0;
}


#include <iostream>
using namespace std;
double p[1100][1100];int s[10000];
int main()
{
	int n,m;int a,b;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
		    a=s[i],b=s[j];
			if(s[i]>s[j])
			{
				p[a][b]=1;
				p[b][a]=0;
			}
			else
			{
				p[a][b]=0;
				p[b][a]=1;
			}
		}
	}
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		for(int j=1;j<=n;j++)
		{
			if(j==a||j==b)continue;
			double paj=p[a][j];
			double pbj=p[b][j];
			p[a][j]=p[b][j]=(paj+pbj)*0.5;
			double pja=p[j][a];
			double pjb=p[j][b];
			p[j][a]=p[j][b]=(pja+pjb)*0.5;
		}
		p[a][b]=p[b][a]=0.5;
	}
	double ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ans+=p[i][j];
		}
	}
	cout<<ans<<endl;

	return 0;
}


#include <iostream>
#include <iomanip>
using namespace std;
double p[1100][1100];int s[10000];
int main()
{
	int n,m;int a,b;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
		    a=s[i],b=s[j];
			if(s[i]>s[j])
			{
				p[a][b]=1;
				p[b][a]=0;
			}
			else
			{
				p[a][b]=0;
				p[b][a]=1;
			}
		}
	}
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		for(int j=1;j<=n;j++)
		{
			if(j==a||j==b)continue;
			double paj=p[a][j];
			double pbj=p[b][j];
			p[a][j]=p[b][j]=(paj+pbj)*0.5;
			double pja=p[j][a];
			double pjb=p[j][b];
			p[j][a]=p[j][b]=(pja+pjb)*0.5;
		}
		p[a][b]=p[b][a]=0.5;
	}
	double ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ans+=p[i][j];
		}
	}
	cout<<fixed<<setprecision(7)<<ans<<endl;

	return 0;
}


#include <iostream>
#include <iomanip>
using namespace std;
double p[1100][1100];int s[10000];
int main()
{
	int n,m;int a,b;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
		    a=s[i],b=s[j];
			if(s[i]>s[j])
			{
				p[a][b]=1;
				p[b][a]=0;
			}
			else
			{
				p[a][b]=0;
				p[b][a]=1;
			}
		}
	}
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		for(int j=1;j<=n;j++)
		{
			if(j==a||j==b)continue;
			double paj=p[a][j];
			double pbj=p[b][j];
			p[a][j]=p[b][j]=(paj+pbj)*0.5;
			double pja=p[j][a];
			double pjb=p[j][b];
			p[j][a]=p[j][b]=(pja+pjb)*0.5;
		}
		p[a][b]=p[b][a]=0.5;
	}
	double ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ans+=p[i][j];
		}
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;

	return 0;
}


#include <iostream>
#include <iomanip>
using namespace std;
double p[1100][1100];int s[10000];
int main()
{
	int n,m;int a,b;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(s[i]>s[j])
			{
				p[i][j]=1;
				p[j][i]=0;
			}
			else
			{
				p[i][j]=0;
				p[j][i]=1;
			}
		}
	}
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		for(int j=1;j<=n;j++)
		{
			if(j==a||j==b)continue;
			double paj=p[a][j];
			double pbj=p[b][j];
			p[a][j]=p[b][j]=(paj+pbj)*0.5;
			double pja=p[j][a];
			double pjb=p[j][b];
			p[j][a]=p[j][b]=(pja+pjb)*0.5;
		}
		p[a][b]=p[b][a]=0.5;
	}
	double ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ans+=p[i][j];
		}
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;

	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long LL;
typedef double ld;

const int MAX=1000+10;
const ld EPS=1e-10;

int n,m,e[MAX];
ld p[MAX][MAX],s[MAX][MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
	int i,j,a,b;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&e[i]);
		p[e[i]][i]=1;
	}
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&a,&b);
		for(j=1;j<=n;++j)
		{
			ld c=p[j][a]+p[j][b];
			p[j][a]=c*0.5;
			p[j][b]=c*0.5;
		}
	}
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			s[i][j]=p[i][j]+s[i][j-1];
	ld ans=0;
	int k,l;
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			for(k=n;k>i;--k)
				for(l=1;l<j;++l)
					if(p[k][l]>EPS)
						ans+=p[i][j]*p[k][l]/(s[k][n]-p[k][j]);
	printf("%lf\n",ans);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long LL;
typedef double ld;

const int MAX=1000+10;
const ld EPS=1e-10;

int n,m,e[MAX];
ld p[MAX][MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
	int i,j,a,b;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%d",&e[i]);
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if(e[i]>e[j])
				p[i][j]=1;
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&a,&b);
		for(j=1;j<=n;++j)
			if(j!=a && j!=b)
			{
				ld c=(p[j][a]+p[j][b])*0.5;
				p[j][a]=p[j][b]=c;
				p[a][j]=p[b][j]=1-c;
			}
		ld c=(p[a][b]+p[b][a])*0.5;
		p[a][b]=p[b][a]=c;
	}
	ld ans=0;
	for(i=1;i<=n;++i)
		for(j=i+1;j<=n;++j)
			ans+=p[i][j];
	printf("%lf\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#define N 1009
using namespace std;
int n,m,a[N];
double p[N][N];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            p[i][j]=(a[i]>a[j]);
    for(int i=1;i<=m;i++)
    {
        int l,r;
        cin>>l>>r;
        p[l][r]=p[r][l]=(p[l][r]+p[r][l])/2;
        for(int j=1;j<=m;j++)
            if(j!=l&&j!=r)
            {
                p[j][l]=p[j][r]=(p[j][l]+p[j][r])/2;
                p[l][j]=p[r][j]=(p[l][j]+p[r][j])/2;
            }
    }
    double res=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            res+=p[i][j];
    printf("%.12lf\n",res);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#define N 1009
using namespace std;
int n,m,a[N];
double p[N][N];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            p[i][j]=(a[i]>a[j]);
    for(int i=1;i<=m;i++)
    {
        int l,r;
        cin>>l>>r;
        p[l][r]=p[r][l]=(p[l][r]+p[r][l])/2;
        for(int j=1;j<=n;j++)
            if(j!=l&&j!=r)
            {
                p[j][l]=p[j][r]=(p[j][l]+p[j][r])/2;
                p[l][j]=p[r][j]=(p[l][j]+p[r][j])/2;
            }
    }
    double res=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            res+=p[i][j];
    printf("%.12lf\n",res);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<ctime>
using namespace std;
#define rep(i,n) for(i=0;i<n;++i)
#define FOR(i,j,k) for(i=j;i<=k;++i)
#define FORD(i,j,k) for(i=j;i>=k;--i)
#define met(i,j) memset(i,j,sizeof(i))
#define fo(i,j) for(typeof(j.begin()) i=j.begin();i!=j.end();++i)
#define PB push_back
#define MK make_pair
#define sz size()
const int inf=2147483647;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
int n,m,a[1005];
double p[1005][1005];
int main()
{
    int i,j,u,v,k;double ans=0;
    scanf("%d%d",&n,&m);
    FOR(i,1,n)scanf("%d",&a[i]);
    FOR(i,1,n)FOR(j,1,n)p[i][j]=(a[i]>a[j]);
    FOR(i,1,m)
    {
        scanf("%d%d",&u,&v);
        p[v][u]=p[u][v]=(p[u][v]+p[v][u])*0.5;
        FOR(k,1,n)
        if(k!=u&&k!=v)
        {
            p[k][u]=p[k][v]=(p[k][v]+p[k][u])*0.5;
            p[u][k]=p[v][k]=(p[v][k]+p[u][k])*0.5;
        }
    }
    FOR(i,1,n)FOR(j,i+1,n)ans+=p[i][j];
    printf("%.10f\n",ans);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<ctime>
using namespace std;
#define rep(i,n) for(i=0;i<n;++i)
#define FOR(i,j,k) for(i=j;i<=k;++i)
#define FORD(i,j,k) for(i=j;i>=k;--i)
#define met(i,j) memset(i,j,sizeof(i))
#define fo(i,j) for(typeof(j.begin()) i=j.begin();i!=j.end();++i)
#define PB push_back
#define MK make_pair
#define sz size()
const int inf=2147483647;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
int n,m,a[1005];
double p[1005][1005];
int main()
{
    int i,j,u,v,k;double ans=0;
    scanf("%d%d",&n,&m);
    FOR(i,1,n)scanf("%d",&a[i]);
    FOR(i,1,n)FOR(j,1,n)p[i][j]=(a[i]>a[j]);
    FOR(i,1,m)
    {
        scanf("%d%d",&u,&v);
        p[v][u]=p[u][v]=(p[u][v]+p[v][u])*0.5;
        FOR(k,1,n)
        if(k!=u&&k!=v)
        {
            p[k][u]=p[k][v]=(p[k][v]+p[k][u])*0.5;
            p[u][k]=p[v][k]=(p[v][k]+p[u][k])*0.5;
        }
    }
    FOR(i,1,n)FOR(j,i+1,n)ans+=p[i][j];
    cout<<ans<<endl;
}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,a,b) for (int i = a; i <= b; ++i)
#define dep(i,a,b) for (int i = a; i >= b; --i)
typedef long long ll;

double f[1010][1010];
int a[1010];
int N,M;

int main() {

	scanf("%d%d", &N, &M);
	rep(i,1,N) scanf("%d", &a[i]);
	rep(i,1,N) rep(j,1,N) f[i][j] = (a[i]>a[j])*1.;
	rep(_,1,M) {
		int x,y;
		scanf("%d%d", &x, &y);
		f[x][y] = f[y][x] = (f[x][y]+f[y][x])/2.;
		rep(i,1,N) {
			if (i == x || i == y) continue;
			f[x][i] = f[i][x] = (f[x][i]+f[i][x])/2.;
			f[y][i] = f[i][y] = (f[y][i]+f[i][y])/2.;
		}
	}
	double ans = 0;
	rep(i,1,N) rep(j,i+1,N) ans += f[i][j];
	printf("%.9f\n", ans);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,a,b) for (int i = a; i <= b; ++i)
#define dep(i,a,b) for (int i = a; i >= b; --i)
typedef long long ll;

double f[1010][1010];
int a[1010];
int N,M;

int main() {

	scanf("%d%d", &N, &M);
	rep(i,1,N) scanf("%d", &a[i]);
	rep(i,1,N) rep(j,1,N) f[i][j] = (a[i]>a[j])*1.;
	rep(_,1,M) {
		int x,y;
		scanf("%d%d", &x, &y);
		f[x][y] = f[y][x] = (f[x][y]+f[y][x])/2.;
		rep(i,1,N) {
			if (i == x || i == y) continue;
			f[i][x] = f[i][y] = (f[i][x] + f[i][y])/2.;
			f[x][i] = 1-f[i][x];
			f[y][i] = 1-f[i][y];
		}
	}
	double ans = 0;
	rep(i,1,N) rep(j,i+1,N) ans += f[i][j];
	printf("%.9f\n", ans);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>

using namespace std;

#define ll long long
#define pi pair<int,int>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define D 1000000007
#define Max (1<<30)
#define LLMAX (1ll<<31)
#define vii vector< vector<ll> >
#define SIZE 11
#define PI 3.141592653589793

int n,m;
int a;
int b;
int wh[1005];
double p[1005][1005];

int main(){
	scanf("%d%d",&n,&m);

	for(int i=1;i<=n;i++)scanf("%d",&wh[i]);
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(wh[i]>wh[j])p[i][j]=1;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		p[a][b]=0.5;

		for(int k=1;k<a;k++)p[k][a]=p[k][b]=(p[k][a]+p[k][b])/2.0;
		for(int k=b+1;k<=n;k++)p[a][k]=p[b][k]=(p[a][k]+p[b][k])/2.0;
		for(int k=a+1;k<b;k++){
			double p1=p[a][k];
			double p2=p[k][b];
			p[a][k]=(p1+1-p2)/2.0;
			p[k][b]=(p2+1-p1)/2.0;
		}
	}

	double rst=0;

	for(int i=1;i<=n;i++){
		for(int k=i+1;k<=n;k++){
			rst+=p[i][k];
		}
	}
	printf("%.9lf",rst);
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>

using namespace std;

#define ll long long
#define pi pair<int,int>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define D 1000000007
#define Max (1<<30)
#define LLMAX (1ll<<31)
#define vii vector< vector<ll> >
#define SIZE 11
#define PI 3.141592653589793

int n,m;
int a;
int b;
int wh[1005];
double p[1005][1005];

int main(){
	scanf("%d%d",&n,&m);

	for(int i=1;i<=n;i++)scanf("%d",&wh[i]);
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(wh[i]>wh[j])p[i][j]=1;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		p[a][b]=0.5;

		for(int k=1;k<a;k++)p[k][a]=p[k][b]=(p[k][a]+p[k][b])/2.0;
		for(int k=b+1;k<=n;k++)p[a][k]=p[b][k]=(p[a][k]+p[b][k])/2.0;
		for(int k=a+1;k<b;k++){
			double p1=p[a][k];
			double p2=p[k][b];
			p[a][k]=(p1+1-p2)/2.0;
			p[k][b]=(p2+1-p1)/2.0;
		}
	}

	double rst=0;

	for(int i=1;i<=n;i++){
		for(int k=i+1;k<=n;k++){
			rst+=p[i][k];
		}
	}
	cout<<rst;
}


#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;

const int M=1e3+5;
double dp[M][M];
int a[M];
ii q[M];

int32_t main()
{
	CS;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++)
		cin>>q[i].fr>>q[i].sc;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			dp[i][j] = (a[i] > a[j]);

	for(int k=1;k<=m;k++){
		int l = q[k].fr;
		int r = q[k].sc;
		if(l>r)
			swap(l,r);
		dp[l][r] = 0.5;
		for(int i=r+1;i<=n;i++)
			dp[r][i] = dp[l][i] = (dp[r][i]+dp[l][i])/2;
		for(int i=1;i<l;i++)
			dp[i][l] = dp[i][r] = (dp[i][l]+dp[i][r])/2;
		for(int i=l+1;i<r;i++){
			double d = (dp[i][r] + 1-dp[l][i])/2;
			dp[i][r] = d;
			dp[l][i] = 1-d;
		}
	}
	double ans = 0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=dp[i][j];
	return cout<<fixed<<setprecision(6)<<ans<<endl,0;
}


#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;

const int M=1e3+5;
double dp[M][M];
int a[M];
ii q[M];

int32_t main()
{
	CS;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++)
		cin>>q[i].fr>>q[i].sc;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			dp[i][j] = (a[i] > a[j]);

	for(int k=1;k<=m;k++){
		int l = q[k].fr;
		int r = q[k].sc;
		dp[l][r] = 0.5;
		for(int i=r+1;i<=n;i++)
			dp[r][i] = dp[l][i] = (dp[r][i]+dp[l][i])/2;
		for(int i=1;i<l;i++)
			dp[i][l] = dp[i][r] = (dp[i][l]+dp[i][r])/2;
		for(int i=l+1;i<r;i++){
			double d = (dp[i][r] + 1-dp[l][i])/2;
			dp[i][r] = d;
			dp[l][i] = 1-d;
		}
	}
	double ans = 0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=dp[i][j];
	return cout<<fixed<<setprecision(6)<<ans<<endl,0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long ll;
inline ll read() {
	char ch = getchar(); ll x = 0; int op = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') op = -1;
	for(; isdigit(ch); ch = getchar()) x = x*10+ch-'0';
	return x*op;
}
inline void write(ll a) {
	if(a < 0) putchar('-'), a = -a;
	if(a >= 10) write(a/10); putchar('0'+a%10);
}
const int N = 1010;
int n, m;
double f[N][N];
int a[N];
int main() {
	n = read(); m = read();
	for(int i = 1; i <= n; i ++) a[i] = read();
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++) f[i][j] = (a[i]>a[j])*1.0;
	while(m --) {
		int x = read(), y = read();
		f[x][y] = f[y][x] = 0.5;
		for(int i = 1; i <= n; i ++) if(i != x && i != y) {
			f[i][x] = f[i][y] = (f[i][x]+f[i][y])/2;
			f[y][i] = f[x][i] = 1-f[i][x];
		}
	}
	double ans = 0;
	for(int i = 1; i <= n; i ++)
		for(int j = i+1; j <= n; j ++) ans += f[i][j];
	printf("%.10lf\n", ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long ll;
inline ll read() {
	char ch = getchar(); ll x = 0; int op = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') op = -1;
	for(; isdigit(ch); ch = getchar()) x = x*10+ch-'0';
	return x*op;
}
inline void write(ll a) {
	if(a < 0) putchar('-'), a = -a;
	if(a >= 10) write(a/10); putchar('0'+a%10);
}
const int N = 1010;
int n, m;
double f[N][N];
int a[N];
int main() {
	n = read(); m = read();
	for(int i = 1; i <= n; i ++) a[i] = read();
	for(int i = 1; i <= n; i ++)
		for(int j = i+1; j <= n; j ++) f[i][j] = (a[i]>a[j])*1.0;
	while(m --) {
		int x = read(), y = read();
		f[x][y] = f[y][x] = 0.5;
		for(int i = 1; i <= n; i ++) if(i != x && i != y) {
			f[i][x] = f[i][y] = (f[i][x]+f[i][y])/2;
			f[y][i] = f[x][i] = 1-f[i][x];
		}
	}
	double ans = 0;
	for(int i = 1; i <= n; i ++)
		for(int j = i+1; j <= n; j ++) ans += f[i][j];
	printf("%.10lf\n", ans);
	return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

typedef long long LL;

#define rep(i,n) for(int i=0;i<n;++i)
typedef double db;
#define mp make_pair
#define pb push_back

const int MAXN = 1111;
int n, m;
db p[ MAXN ][ MAXN ];
int a[ MAXN ];

int main(){
	while( cin >> n >> m) {
		for(int i=1;i<=n;++i) scanf("%d",a + i);
		memset( p, 0, sizeof p);
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
			if( a[i] > a[j] ) p[ i ][ j ] = 1;
		for(int c=0;c<m;++c) {
			int x, y; scanf("%d%d", &x, &y);
			p[ x ][ y ] = p[ y ][ x ] = 1.0 / 2;
			for(int i = 1; i <= n; ++ i) if(i!=x && i!=y) {
				db pxi = p[x][i], pyi = p[y][i], pix = p[i][x] , piy = p[i][y];
				p[x][i] = 0.5 * pxi + 0.5 * pyi,
				p[i][x] = 0.5 * pix + 0.5 * piy,
				p[y][i] = 0.5 * pyi + 0.5 * pxi;
				p[i][y] = 0.5 * piy + 0.5 * pix;
			}
		}
		db ans = .0;
		for(int i=2;i<=n;++i) for(int j=1;j<i;++j) ans += p[ i ][ j ];
		printf("%.10f\n", ans);
	}
	return 0;
}


//@HelloElwin-20180811
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n, v[1005], f[1005], flg;
bool bk[1005];

void dfs(int u){
	if(bk[u]){
		if(f[u]){
			flg=-1;
			return;
		}
		flg=u;
		return;
	}
	bk[u]=true;
	dfs(v[u]);
	if(flg>0){
		f[u]=u;
		if(u==flg)flg=-1;
	}else if(flg==-1){
		f[u]=f[v[u]];
	}
}

int main(){

	scanf("%d", &n);

	for(int i=1; i<=n; i++){
		scanf("%d", v+i);
	}

	for (int i=1; i<=n; i++) if (!bk[i]) flg=0, dfs(i);

	for (int i=1; i<=n; i++) printf("%d ", f[i]);

	return 0;
}


//@HelloElwin-20180811
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n, v[1005], f[1005], flg;
bool bk[1005];

void dfs(int u){
	if(bk[u]){
		flg=u;
		return;
	}
	bk[u]=true;
	dfs(v[u]);
	if(flg>0){
		f[u]=u;
		if(u==flg)flg=-1;
	}else if(flg==-1){
		f[u]=f[v[u]];
	}
}

int main(){

	scanf("%d", &n);

	for(int i=1; i<=n; i++){
		scanf("%d", v+i);
	}

	for (int i=1; i<=n; i++) if (!bk[i]) flg=0, dfs(i);

	for (int i=1; i<=n; i++) printf("%d ", f[i]);

	return 0;
}


#include<bits/stdc++.h>
#define N 200007
#define ll long long
using namespace std;

int n, kt, p[N], dd[N], dem[N];

void DFS(int u)
{
    dem[u]++;
    if(dem[u] == 2)
    {
        cout << u <<" ";
        kt = 1;
    }
    if(kt == 1) return;
    DFS(p[u]);
}
main()
{
    //freopen("B.inp","r",stdin);

    cin >> n;
    for(int i=1; i<=n; i++) cin >> p[i];

    for(int i=1; i<=n; i++)
    {
        memset(dem, 0, sizeof(dem));
        kt = 0;
        DFS(i);
    }
}


#include<bits/stdc++.h>
#define N 200007
#define ll long long
using namespace std;

int n, p[N], dd[N];

main()
{
    //freopen("B.inp","r",stdin);

    cin >> n;
    for(int i=1; i<=n; i++) cin >> p[i];

    for(int i=1; i<=n; i++)
    {
        memset(dd, 0, sizeof(dd));
        dd[i] = 1;
        for(int j=1; j<=n; j++)
        {
            if(dd[p[j]] == 0) dd[p[j]] = 1;
            else
            {
                cout << p[j] <<" ";
                break;
            }
        }

    }
}


#include<bits/stdc++.h>
#define N 200007
#define ll long long
using namespace std;

int n, kt, p[N], dd[N];

main()
{
    //freopen("B.inp","r",stdin);

    cin >> n;
    for(int i=1; i<=n; i++) cin >> p[i];

    for(int i=1; i<=n; i++)
    {
        memset(dd, 0, sizeof(dd));
        kt = 0;
        dd[i] = 1;
        int x = i;
        while(dd[p[x]] == 0)
        {
            dd[p[x]] = 1;
            x = p[x];
            if(dd[x] == 1)
            {
                kt = 1;
                cout << x <<" ";
                break;
            }
        }
        if(kt == 0) cout << x <<" ";
    }
}


#include<bits/stdc++.h>
#define N 200007
#define ll long long
using namespace std;

int n, p[N], dd[N];

main()
{
    //freopen("B.inp","r",stdin);

    cin >> n;
    for(int i=1; i<=n; i++) cin >> p[i];

    for(int i=1; i<=n; i++)
    {
        memset(dd, 0, sizeof(dd));
        dd[i] = 1;
        int x = i;
        while(dd[p[x]] == 0)
        {
            x = p[x];
            dd[p[x]] = 1;
        }
        cout << x <<" ";
    }
}


#include<cstdio>
#include<cstring>
const int MAXN=1001;
int n;
bool vis[MAXN];
int next[MAXN];
int dfs(int node)
{
	if(vis[node]) return node;
	vis[node]=true;
	return dfs(next[node]);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",next+i);
	for(int i=1;i<=n;i++)
	{
		memset(vis,false,sizeof(vis));
		printf("%d ",dfs(i));
	}
	return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=1001;
int n;
bool vis[MAXN];
int next[MAXN];
int dfs(int node)
{
	if(vis[node]) return node;
	vis[node]=true;
	return dfs(next[node]);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",next+i);
	for(int i=1;i<=n;i++)
	{
		memset(vis,false,sizeof(vis));
		printf("%d ",dfs(i));
	}
	return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;

int n;

const int MAXN = 1005;

struct edge{
	int u,v,nxt;
}e[MAXN<<1];int head[MAXN];int cnt=0;int vis[MAXN];

inline void add(int u,int v){
	e[++cnt].u = u;e[cnt].v = v;e[cnt].nxt = head[u];head[u] = cnt;
}

inline void dfs(int x){
	vis[x]++;
	if(vis[x] == 2){
		printf("%d ",x);
		return ;
	}
	for(int i=head[x];i;i=e[i].nxt){
		int v = e[i].v;
		dfs(v);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		int x;scanf("%d",&x);
		add(i,x);
	}
	for(int i=1;i<=n;++i){
		memset(vis,0,sizeof vis);
		dfs(i);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,b[1010],ind[1010]={};
int main()
{
    scanf("%d",&n);
    memset(ind,0,sizeof(ind));
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        ++ind[b[i]];
    }
    queue<int> q;
    for (int i=1;i<=n;i++)
        if (!ind[i])
            q.push(i);
    while (!q.empty())
    {
        int t=q.front();
        q.pop();
        --ind[b[t]];
        if (!ind[b[t]])
            q.push(b[t]);
    }
    for (int i=1;i<=n;i++)
    {
        int t=i;
        while (!ind[t])
            t=b[t];
        printf("%d ",t);
    }
    return 0;//luogu failed
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, a[1010];
bool chk[1010];
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	for(int i=1; i<=n; i++) {
		memset(chk,0,sizeof(chk));
		int j = i;
		while(!chk[j]) {
			chk[j] = 1;
			j = a[j];
		}
		printf("%d ", j);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[1001],b[1001],ans[1001];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(ans,0,sizeof(ans));
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n-1;i++)
    {
        b[a[i]]=a[i+1];
    }
    if(b[1]==0)b[1]=a[0];
    if(b[a[n]]==0)b[a[n]]=1;
    //for(int i=1;i<=n;i++)printf("b[%d]=%d\n",i,b[i]);
    for(int i=1;i<=n;i++)
    {
        ans[i]++;
        int j=i;
        while(ans[b[j]]==0)
        {
            ans[b[j]]++;
            j=b[j];
        }
        printf("%d ",b[j]);
        memset(ans,0,sizeof(ans));
    }
    printf("\n");

}


#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define mod 10003
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1<<30;
const int maxn = 1000003;
const double eps = 1e-8;
int t,n,m,q;
int a[maxn],v[maxn];
int ok(int x)
{
    memset(v,0,sizeof(v));
    int now=x;
    while(1)
    {
        v[now]++;
        if(v[now]==2) return now;
        now=a[now];
    }
}
int main()
{
    while(cin>>n)
    {
        memset(v,0,sizeof(v));
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++)
        {
            if(i==1) cout<<ok(i); else cout<<' '<<ok(i);
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, p[1002];
bool cyc[1002] = {};
int memo[1002] = {};
int f(int i, set<int> v) {
    if (cyc[i]) return i;
    if (memo[i] > 0) return memo[i];
    if (v.find(p[i]) != v.end()) return memo[i] = p[i];
    v.insert(i);
    int x = f(p[i], v);
    return memo[i] = x;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) { scanf(" %d", &p[i+1]); }
    for (int i = 1; i <= n; i++) {
        if (cyc[i]) continue;
        int fast = p[p[i]], slow = p[i];
        while (fast != slow) fast = p[p[fast]], slow = p[slow];
        for (int k = p[slow]; k != slow; k = p[k])  cyc[k] = true;
        cyc[slow] = true;
    }
    for (int i = 1; i <= n; i++)
        if (cyc[i]) printf("%d ", i);
        else printf("%d ", f(i, set<int>()));
}


#include <bits/stdc++.h>
using namespace std;
int n, p[1002];
bool seen[1002] = {}, memo[1002] = {};
int f(int i, set<int> v) {
    if (memo[i]) return i;
    if (v.find(p[i]) != v.end()) return p[i];
    v.insert(i);
    int x = f(p[i], v);
    return x;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) { scanf(" %d", &p[i+1]); }
    for (int i = 1; i <= n; i++) {
        if (seen[i]) continue;
        int j = i;
        while (!seen[j]) {
            seen[j] = true;
            j = p[j];
        }
        memo[j] = true;
        for (int k = p[j]; k != j; k = p[k]) memo[k] = true;
    }
    for (int i = 1; i <= n; i++)
        if (memo[i]) printf("%d ", i);
        else printf("%d ", f(i, set<int>()));
}


#include <bits/stdc++.h>
using namespace std;
int n, p[1002];
bool seen[1002] = {}, cyc[1002] = {};
int memo[1002] = {};
int f(int i, set<int> v) {
    if (cyc[i]) return i;
    if (memo[i] > 0) return memo[i];
    if (v.find(p[i]) != v.end()) return memo[i] = p[i];
    v.insert(i);
    int x = f(p[i], v);
    return memo[i] = x;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) { scanf(" %d", &p[i+1]); }
    for (int i = 1; i <= n; i++) {
        if (seen[i]) continue;
        int j = i;
        while (!seen[j]) {
            seen[j] = true;
            j = p[j];
        }
        cyc[j] = true;
        for (int k = p[j]; k != j; k = p[k]) cyc[k] = true;
    }
    for (int i = 1; i <= n; i++)
        if (cyc[i]) printf("%d ", i);
        else printf("%d ", f(i, set<int>()));
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n; int p[n+1];
    for (int i=1; i<=n; i++) scanf(" %d", &p[i]);
    for (int i=1; i<=n; i++) {
        int b[n+1] = {};
        int j = i;
        while(!b[j]) b[j] = 1, j = p[j];
        printf("%d ", j);
    }
}


#include <bits/stdc++.h>
using namespace std;
int n, p[1002];
// int memo[1002] = {};
int f(int i, set<int> v) {
    if (p[i] == i) return i;
    // if (memo[i] > 0) return memo[i];
    if (v.find(p[i]) != v.end()) return p[i]; //memo[i] = p[i];
    v.insert(i);
    int x = f(p[i], v);
    return x; // memo[i] = x;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) { scanf(" %d", &p[i+1]); }
    for (int i = 0; i < n; i++) printf("%d ", f(i+1, set<int>()));
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int n;
int p[1005];
bool v[1005];

int main(){
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&p[i]);

	int now;
	for(i=1;i<=n;i++){
		memset(v,0,sizeof(v));
		now=i;
		while(!v[now]){
			v[now]=1;
			now=p[now];
		}
		printf("%d ",now);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=1010;
struct edge{
	int next,to;
}e[maxn];
int n,head[maxn],cnt;
bool vis[maxn];
void add(int x,int y)
{
	e[++cnt].next=head[x];
	e[cnt].to=y;
	head[x]=cnt;
}
int dfs(int x)
{
	vis[x]=1;
	for(int i=head[x];i;i=e[i].next)
		if(vis[e[i].to])
			return e[i].to;
		else
			return dfs(e[i].to);
}
int main()
{
	scanf("%d",&n);
	for(int x,i=1;i<=n;i++)
	{
		scanf("%d",&x);
		add(i,x);
	}
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		printf("%d ",dfs(i));
	}
	printf("\n");
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 100000001
#define int long long
using namespace std;
int n,h,q,l,r,k;
signed main()
{
    scanf("%lld%lld%lld%lld%lld",&n,&h,&l,&r,&q);
    for(int i=1;i<=q;i++)
	{
        int _,__,____,___,ans=0;
        scanf("%lld%lld%lld%lld",&_,&__,&____,&___);
        ans=abs(_-____);
        if(_==____)
		{
            printf("%lld\n",abs(__-___));
            continue;/*ladsjlgdj'o
            aso;yerjpl'DAH
            oaet;ujBN
    gqejlka54sjf8utjsrjgnhsfgedytedhgdsujtdrgasdgfeasusdf
    49etjgs;l
    gnfsdl;k;
    payk*/
        }
        if(__<=r&&__>=l&&___<=r&&___>=l)
		{
            ans+=abs(__-___);/*a;ltiuj4e[opjmals'gjo*/
            printf("%lld\n",ans);
            continue;
        }
        int ans1=abs(l-__)+abs(l-___),ans2=abs(r-__)+abs(r-___);
        ans+=min(ans1,ans2);
        printf("%lld\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include<iostream>
#include <map>
using namespace std;
#define N 1010
map<int,int>mp;
long long n,m,p[N],ans=0;
int vis[N];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		int u=i;
		while(1){
			vis[u]++;
			if(vis[u]>1){
				printf("%d ",u);
				break;
			}
			u=p[u];
		}
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
	int n;
	cin>>n;
	vector<int> p(n+1);
	for(int i=1;i<n+1;i++){
		int x;
		cin>>x;
		p[i]=x;
	}
	int n2=1;
	while(n2!=n+1){
		vector<bool> c(n+1);
		int i = p[n2];
		c[i]=true;
		while(true){
			if(c[p[i]]){cout<<(p[i])<<endl;break;}
			else c[p[i]] = true;
			i = p[i];
		}
		n2++;
	}

	return 0;
}


#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
	int n;
	cin>>n;
	vector<int> p(n+1);
	for(int i=1;i<n+1;i++){
		int x;
		cin>>x;
		p[i]=x;
	}
	int n2=1;
	while(n2!=n+1){
		vector<bool> c(n+1);
		c[n2]=true;
		int i = p[n2];
		c[i] = true;
		while(true){
			if(c[p[i]]){cout<<(p[i])<<endl;break;}
			else c[p[i]] = true;
			i = p[i];
		}
		n2++;
	}

	return 0;
}


#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
	int n;
	cin>>n;
	vector<int> p(n+1);
	for(int i=1;i<n+1;i++){
		int x;
		cin>>x;
		p[i]=x;
	}
	int n2=1;
	while(n2!=n+1){
		vector<bool> c(n+1);
		int i = p[n2];
		c[i]=true;
		while(true){
			if(c[p[i]]){cout<<(p[i]);break;}
			else c[p[i]] = true;
			i = p[i];
		}
		n2++;
	}

	return 0;
}


# include<cstdio>
#include<cstring>
#include<iostream>
#undef main

using namespace std;
int main()
{
	bool vis[1001];
	int n;
	int a[1001];
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++)	scanf("%d", a+i);
	for(int i = 1; i <= n; i ++)
	{
		memset(vis, 0, sizeof(vis));
		int j;
		for(j = i; !vis[j]; vis[j] = 1, j = a[j])
		{
		}
		printf("%d ", j);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[1001],b[1001],ans[1001];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(ans,0,sizeof(ans));
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n-1;i++)
    {
        b[a[i]]=a[i+1];
    }
    if(b[1]==0)b[1]=a[0];
    if(b[a[n-1]]==0)b[a[n-1]]=a[0];
    //for(int i=1;i<=n;i++)printf("b[%d]=%d\n",i,b[i]);
    for(int i=1;i<=n;i++)
    {
        ans[i]++;
        int j=i;
        while(ans[b[j]]==0)
        {
            ans[b[j]]++;
            j=b[j];
        }
        printf("%d ",b[j]);
        memset(ans,0,sizeof(ans));
    }
    printf("\n");

}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n;
int book[1005],inf[1005];
void pret()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>book[i];
	return;
}
int main()
{
	int stu;
	pret();
	for(int i=1;i<=n;i++)
	{

		memset(inf,0,sizeof(inf));
		stu=i;
		while(inf[stu]==0)
		{
			inf[stu]=1;
			stu=book[stu];
		}
		cout<<stu<<" ";
	 }
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<queue>
using namespace std;
int pd[10001],last[10001];
int tot,ans;
int n;
int p[10001];
struct edge{
	int to,next;
}e[100001];
int add(int x,int y){
	e[++tot].to=y;
	e[tot].next=last[x];
	last[x]=tot;
}
void search(int x){
	memset(pd,0,sizeof(pd));
	ans=0;
	queue<int> q;
	q.push(x);
	while(!q.empty()){
		int first=q.front();q.pop();
		pd[first]++;
		if(pd[first]==2){
			printf("%d ",first);
			pd[first]=1;
			++ans;
			return;
		}
		for(int i=last[first];i;i=e[i].next){
			int u=e[i].to;
		//	printf("%d ",u);
			q.push(u);
		}
	}
}//asdfuhaugfubakjdhfiah
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&p[i]);
		add(i,p[i]);
	}
	for(int i=1;i<=n;i++) search(i);
	return 0;//aidhf9audfh
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int p[1010];
bool vis[1010];
int main()
{
	int n,now;
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&p[i]);
	for(int i=1;i<=n;i++){
		memset(vis,false,sizeof(vis));
		now=i;
		while(1){
			if(vis[now]) break;
			vis[now]=true;
			now=p[now];
		}
		printf("%d ",now);
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[1001],b[1001],ans[1001];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(ans,0,sizeof(ans));
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n-1;i++)
    {
        b[a[i]]=a[i+1];
    }
    if(b[1]==0)b[1]=a[0];
    if(b[n]==0)b[n]=1;
    //for(int i=1;i<=n;i++)printf("b[%d]=%d\n",i,b[i]);
    for(int i=1;i<=n;i++)
    {
        ans[i]++;
        int j=i;
        while(ans[b[j]]==0)
        {
            ans[b[j]]++;
            j=b[j];
        }
        printf("%d ",b[j]);
        memset(ans,0,sizeof(ans));
    }
    printf("\n");

}


#include<bits/stdc++.h>
using namespace std;
int p[1001];
bool g[1001];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)
	{
		memset(g,false,sizeof(g));
		int j;
		for(j=i;!g[j];j=p[j])
			g[j]=true;
		printf("%d ",j);
	}
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,s;
    cin>>n;
    long long a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>b[i];
        a[i]=0;
    }
    for(i=0;i<n;i++)
    {
        s=i+1;
        while(a[s-1]!=1)
        {
            a[s-1]=a[s-1]++;
            s=b[s-1];
        }
        cout<<s<<" ";
        for(j=0;j<n;j++)
        {
            a[j]=0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,s;
    cin>>n;
    long long a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>b[i];
        a[i]=0;
    }
    for(i=0;i<n;i++)
    {
        s=i+1;
        while(a[s-1]!=1)
        {
            a[s-1]=1;
            s=b[s-1];
        }
        cout<<s<<" ";
        for(j=0;j<n;j++)
        {
            a[j]=0;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 2050 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
int a[MAXN];
int b[MAXN];
int c[MAXN];
int qis[MAXN];
int ans = 0;
int main()
{
    int n, h, k;
    scanf("%d", &n);
    memset(qis, 0, sizeof(qis));
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        memset(qis, 0, sizeof(qis));
        int flag = i;
        while (!qis[flag])
        {
            qis[flag] = 1;
            flag = a[flag];
        }
        if(i==1)
        printf("%d", flag);
        else
        {
            printf(" %d", flag);
        }
    }
    //system("pause");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 22050 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
int a[MAXN];
int b[MAXN];
int c[MAXN];
int qis[MAXN];
int ans = 0;
int main()
{
    int n, h, k;
    scanf("%d", &n);
    memset(qis, 0, sizeof(qis));
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        memset(qis, 0, sizeof(0));
        int flag = i;
        while (!qis[flag])
        {
            qis[flag] = 1;
            flag = a[flag];
        }
        if(i==1)
        printf("%d", flag);
        else
        {
            printf(" %d", flag);
        }
    }
    printf("\n");
    //system("pause");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 32050 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
int a[MAXN];
int b[MAXN];
int c[MAXN];
bool qis[MAXN];
int ans = 0;
int main()
{
    int n, h, k;
    scanf("%d", &n);
    memset(qis, false, sizeof(qis));
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        memset(qis, false, sizeof(qis));
        int flag = i;
        while (!qis[flag])
        {
            qis[flag] = true;
            flag = a[flag];
        }
        if(i==1)
        printf("%d", flag);
        else
        {
            printf(" %d", flag);
        }
    }
    system("pause");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 1050 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
int a[MAXN];
int b[MAXN];
int c[MAXN];
bool qis[MAXN];
int ans = 0;
int main()
{
    int n, h, k;
    scanf("%d", &n);
    memset(qis, false, sizeof(qis));
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        memset(qis, false, sizeof(0));
        int flag = i;
        while (!qis[flag])
        {
            qis[flag] = true;
            flag = a[flag];
        }
        if(i==1)
        printf("%d", flag);
        else
        {
            printf(" %d", flag);
        }
    }
    printf("\n");
    //system("pause");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 2050 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
int a[MAXN];
int b[MAXN];
int c[MAXN];
bool qis[MAXN];
int ans = 0;
int main()
{
    int n, h, k;
    scanf("%d", &n);
    memset(qis, false, sizeof(qis));
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        memset(qis, false, sizeof(qis));
        int flag = i;
        while (!qis[flag])
        {
            qis[flag] = true;
            flag = a[flag];
        }
        if(i==1)
        printf("%d", flag);
        else
        {
            printf(" %d", flag);
        }
    }
    system("pause");
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#define inf 200
#define maxn 2000100
using namespace std;
int a[1005];
int vis[1005];
int pre;
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	pre=1;
	for(int j=1;j<=n+1;j++)
		{
			vis[pre]++;
			if(vis[pre]==2)
				break;
			pre=a[pre];
		}
	printf("%d",pre);
	for(int i=2;i<n;i++)
		{
			pre=i;
			memset(vis,0,sizeof(vis));
			for(int j=1;j<=n+1;j++)
				{
					vis[pre]++;
					if(vis[pre]==2)
						break;
					pre=a[pre];
				}
			printf(" %d",pre);
		}

		memset(vis,0,sizeof(vis));
		pre=n;
		for(int j=1;j<=n+1;j++)
		{
			vis[pre]++;
					if(vis[pre]==2)
						break;
					pre=a[pre];
		}
		printf(" %d\n",pre);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#define inf 200
#define maxn 2000100
using namespace std;
int a[1005];
int vis[1005];
int pre;
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	pre=1;
	for(int j=1;j<=n+1;j++)
		{
			vis[pre]++;
			if(vis[pre]==2)
				break;
			pre=a[pre];
		}
	printf("%d",pre);
	for(int i=2;i<=n;i++)
		{
			pre=i;
			memset(vis,0,sizeof(vis));
			for(int j=1;j<=n+1;j++)
				{
					vis[pre]++;
					if(vis[pre]==2)
						break;
					pre=a[pre];
				}
			printf(" %d",pre);
		}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[1001],v[1001],curr;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		memset(v,0,sizeof v);
		curr=i;v[i]=1;
		while(v[curr]<2){
			curr=a[curr];
			v[curr]++;
		}
		printf("%d ",curr);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[1001],v[1001],curr;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		memset(v,0,sizeof v);
		curr=i;v[i]=1;
		while(v[curr]<2){
			curr=a[curr];
			v[curr]++;
		}
		printf("%d ",curr);
	}
}


#include <iostream>

using namespace std;

const int maxn = 1005;

int mark[maxn],to[maxn];

int main()
{
    int n,p;
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> to[i];
    }
    for(int i = 1;i <= n;i++)
    {
        fill(mark+1,mark+n+1,0);
        mark[i]++;
        int j = i;
        for(;;){
            j = to[j];
            mark[j]++;
            if(mark[j] == 2) break;
        }
        cout << j << " ";
    }
    return 0;
}