#include<bits/stdc++.h>
//#define int long long
#define rint register int
#define UF(i,x,y) for(rint i=x;i<=y;i++)
#define DF(i,x,y) for(rint i=x;i>=y;i--)
#define ce continue
#define inf 0x7fffffff
#define sf scanf
#define pf printf
#define N 3005
#define mod 1000000007
using namespace std;
int u[N],v[N],n,m,cnt,G[N][N],num,city[N];
bool b[2*N],vis[N],voice,flag;
inline void dfs(int now)
{
	if(vis[now]) return;
	vis[now]=1;
	UF(i,1,n) if(G[now][i]) dfs(i);
}
inline void work()
{
	UF(i,1,m) G[u[i]][v[i]]=(b[i])?2:1;
	voice=1;
	UF(i,1,m)
	{
		if(G[u[i]][v[i]]==2)
		{
			memset(vis,0,sizeof(vis));
			dfs(city[1]);
			UF(j,1,num) if(vis[city[j]]==0)
			{
				voice=0;
				break;
			}
			
		}
		if(G[u[i]][v[i]]==1)                   
		{
			memset(vis,0,sizeof(vis));
			G[u[i]][v[i]]=0;
			dfs(city[1]);
			UF(j,1,num) if(vis[city[j]]==0)
			{
				voice=0;
				break;
			}
			G[u[i]][v[i]]=1;
		}
	}
	cnt=(cnt+voice)%mod;
}
//For G
//0 no
//1 road
//2 protected road
signed main()
{
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	sf("%d%d",&n,&m);
	UF(i,1,m) sf("%d%d",&u[i],&v[i]);
	b[n+m]=1;
	while(!b[0])
	{
		num=0;
		UF(i,m+1,n+m) if(b[i]) city[++num]=i-m;
		if(num) work(); 
		int j=n+m;
		while(b[j]) b[j--]=0;
		b[j]=1;
	}
	pf("%d\n",cnt%mod);
	fclose(stdin);fclose(stdout);
	return 0;
}
//For b
//0 set
//1~m road
//m+1~n+m city