#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 510;   int m;   long long n, ans;   int cnt, head[N];   struct edge {     int to, next;   } e[1010];   void ade(int u, int v) {     e[++cnt] = (edge){v, head[u]};     head[u] = cnt;   }   long long getsize(long long num) {     if (num > n) return 0;     long long tl = num, tr = num;     int m1 = 0, m2 = 0;     while (tl * 2 <= n) tl = tl * 2, m1++;     while (tr * 2 + 1 <= n) tr = tr * 2 + 1, m2++;     if (tl <= tr)       return (1 << (m2 + 1)) - 1;     else       return (1 << (m2 + 1)) - 1 + n - tl + 1;   }   map<int, int> vis;   int tot;   long long val[N];   void build(int x) {     val[vis[x]] = 1;     int to = x << 1;     if (to <= n && vis[to]) {       build(to);       ade(vis[x], vis[to]);       ade(vis[to], vis[x]);     } else       val[vis[x]] += getsize(to);     to = x << 1 | 1;     if (to <= n && vis[to]) {       build(to);       ade(vis[x], vis[to]);       ade(vis[to], vis[x]);     } else       val[vis[x]] += getsize(to);   }   int bk[N];   void dfs(int now, long long w) {     bk[now] = 1;     for (int i = head[now]; i; i = e[i].next) {       int to = e[i].to;       if (bk[to]) continue;       dfs(to, w);       ans = (ans + w * val[to] % mod) % mod;     }     bk[now] = 0;   }   int main() {     cin >> n >> m;     if (!m) {       ans = n * n % mod;       ans = (ans % mod + mod) % mod;       printf( %lld n , ans);     } else {       for (int i = 1; i <= m; i++) {         int a, b;         cin >> a >> b;         if (!vis[a]) vis[a] = ++tot;         if (!vis[b]) vis[b] = ++tot;         ade(vis[a], vis[b]);         ade(vis[b], vis[a]);         while (a) {           a >>= 1;           if (!vis[a]) vis[a] = ++tot;         }         while (b) {           b >>= 1;           if (!vis[b]) vis[b] = ++tot;         }       }       build(1);       for (int i = 1; i <= tot; i++) dfs(i, val[i]);       for (int i = 1; i <= tot; i++) ans = (ans + val[i] * val[i] % mod) % mod;       printf( %lld n , ans);     }     return 0;   }   