#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
bool vis[500010];
vector<int> edge[500010];
int main(){
    freopen("barrack.in","r",stdin);
    freopen("barrack.out","w",stdout);
    int n,m;
    cin >> n >> m;
    bool if_sp_A=1;
    for(int i=1;i<=m;i++){
        int a,b;
        cin >> a >> b;
        if(a!=i||b!=i+1){
            if_sp_A=false;
        }
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    if(if_sp_A){
        int ans=1;
        n-=1;
        while(n--){
            ans=(ans<<2)+1;
            ans=ans%mod;
        }
        cout << ans << endl;
        return 0;
    }
    //BAOLI
    cout << 12;
    fclose(stdin);
    fclose(stdout);
    return 0;
}
