#include <bits/stdc++.h>
const int MOD = 1000000007;
inline int add(int x, int y) {
  int r = x + y;
  if (r >= MOD) r -= MOD;
  return r;
}
inline int mul(int x, int y) { return (long long)x * (long long)y % MOD; }
using namespace std;
int N, M;
int getsize(int u) {
  if (u > N) return 0;
  int i, dlch = 0, drch = 0;
  i = u;
  while (i * 2 <= N) i = i * 2, dlch++;
  i = u;
  while (i * 2 + 1 <= N) i = i * 2 + 1, drch++;
  if (dlch == drch) return (1 << (dlch + 1)) - 1;
  return 1 + getsize(u * 2) + getsize(u * 2 + 1);
}
int Ans = 0, nstart;
map<int, vector<int> > G;
map<int, bool> vis, marked;
void mark(int u) {
  while (u) marked[u] = 1, u >>= 1;
}
void dfs(int u) {
  vis[u] = 1;
  if (!marked[u]) {
    Ans = add(Ans, mul(nstart, getsize(u)));
    if (u != 1 && !vis[u >> 1]) dfs(u >> 1);
  } else {
    Ans = add(Ans, nstart);
    if (u != 1 && !vis[u >> 1]) dfs(u >> 1);
    if (u * 2 <= N && !vis[u * 2]) dfs(u * 2);
    if (u * 2 + 1 <= N && !vis[u * 2 + 1]) dfs(u * 2 + 1);
    int i, v;
    vector<int> &nxt = G[u];
    for (i = 0; i < nxt.size(); i++)
      if (!vis[v = nxt[i]]) dfs(v);
  }
  vis[u] = 0;
}
int main() {
  int i, u, v;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= M; i++) {
    scanf("%d%d", &u, &v);
    mark(u), mark(v);
    G[u].push_back(v), G[v].push_back(u);
  }
  mark(1);
  map<int, bool>::iterator it;
  for (it = marked.begin(); it != marked.end(); it++)
    if (it->second) {
      u = it->first;
      nstart = 1, dfs(u);
      if (u * 2 <= N && !marked[u * 2]) nstart = getsize(u * 2), dfs(u * 2);
      if (u * 2 + 1 <= N && !marked[u * 2 + 1])
        nstart = getsize(u * 2 + 1), dfs(u * 2 + 1);
    }
  printf("%d", Ans);
}
