#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

static const int N = 5e5+10;
static const int p = 1e9+7;

ll n, m, ans;
struct nod {
	ll id, du;
	vector<ll> son;
	inline bool operator<(const nod &X) const {
		return du < X.du; 
	}
} a[N];

inline ll read() {
	register ll s = 0ll;
	register bool m = false;
	register char ch = getchar();
	while(! isdigit(ch)) {
		if(ch == '-')
			m = true;
		ch = getchar();
	}
	while(isdigit(ch)) s = (s << 1ll) + (s << 3ll) + (ch ^ 48ll), ch = getchar();
	return m ? -s : s;
}

inline ll _QP(register ll a, register ll b) {
	register ll res = 1ll%p;
	for(; b;b >>= 1ll, a = a*a%p) if(b & 1ll) res = res*a%p;
	return res%p;
}

//#define PB push_back
//inline void _Add(const ll &u, const ll &v) {
//	a[u].son.PB(v); a[u].du ++;
//}

signed main(int argc, char const* argv[]) {
	freopen("barrack.in", "r", stdin);
	freopen("barrack.out", "w", stdout);
//	cout << _QP(2, 10);
	n = read(), m = read();
	register bool f = true;
	for(register int i = 1;i <= n; ++i) a[i].id = i;
	for(register int i = 1;i <= m; ++i) {
		register ll u = read(), v = read();
		if(v-1 != u) f = false;
//		_Add(u, v), _Add(v, u);
	}
	if(f && m == n-1) {
		register ll tmp = n*_QP(2, m) %p;
		ans += tmp;
//		cout << "ans=" << ans << endl;
		for(register ll i = 1;i <= n; ++i) {
			for(register ll j = i+1;j <= n; ++j) {
				register ll tmp1 = _QP(2ll, m-(j-i))%p;
//				printf("tmp1=%lld\n", tmp1);
				register ll tmp2 = _QP(2ll, (j-1ll-i))%p;
				ans = (ans + tmp1*tmp2)%p;
			}}
		printf("%lld\n", ans);
		return 0;
	}
	else {
		register ll tmp1 = n*_QP(2, m)%p;
		register ll tmp2 = ((n*(n-1)%p)>>1ll)*_QP(2, m-1)%p;
		printf("%lld\n", (tmp1+tmp2)%p);
	}
	return 0;
}
#if false
find du == 1
#endif

