#include <bits/stdc++.h>
using namespace std;
struct rd {
  int next, to;
} road[4010];
int n, m, cnt, d, tot, head[1010], num[1010], tmp, u[11], v[11];
bool flag[1010];
inline void addedge(int x, int y) {
  road[++tot].next = head[x];
  road[tot].to = y;
  head[x] = tot;
}
map<int, int> mp;
inline int insert(int x) {
  if (mp[x] == 0) mp[x] = ++cnt;
  return mp[x];
}
inline int query(int x) {
  int deep = 0, p = x, q = x, t;
  while (p) p = p >> 1, deep++;
  t = deep;
  int sum = (1 << d - deep + 1) - 1;
  while (t < d) q = q << 1 | 1, t++;
  return sum - min(max(q - n, 0), 1 << (d - deep));
}
inline void dfs1(int x, int fa) {
  for (int now = head[x]; now; now = road[now].next)
    if (road[now].to != fa) num[x] -= num[road[now].to], dfs1(road[now].to, x);
}
inline void dfs(int x) {
  flag[x] = 1;
  tmp = (tmp + num[x]) % 1000000007;
  for (int now = head[x]; now; now = road[now].next)
    if (flag[road[now].to] == 0) dfs(road[now].to);
  flag[x] = 0;
}
int main() {
  cin >> n >> m;
  while ((1 << d) <= n) d++;
  insert(-1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    insert(-u[i]);
    insert(-v[i]);
  }
  map<int, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); ++it) {
    int x = it->first, id = it->second;
    if (x != -1) addedge(id, insert(x / 2)), addedge(insert(x / 2), id);
    num[id] = query(-x);
  }
  dfs1(1, 0);
  for (int i = 1; i <= m; i++)
    addedge(insert(-u[i]), insert(-v[i])),
        addedge(insert(-v[i]), insert(-u[i]));
  int ans = 0;
  for (it = mp.begin(); it != mp.end(); it++) {
    tmp = 0;
    dfs(it->second);
    ans = (ans + 1ll * num[it->second] * tmp) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}
