#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
const int Mod = 1e9 + 7;
int deep(int x) {
  if (x == 1)
    return 1;
  else
    return deep(x >> 1) + 1;
}
int maxdeep;
int n, m, ans;
int u[2333], v[2333];
vector<int> edge[2333];
int size(int x) {
  if (!x) return 0;
  int deepx = deep(x);
  int res = (1 << (maxdeep - deep(x))) - 1;
  int L = x, R = x;
  for (; deepx < maxdeep; deepx++) L = L * 2, R = R * 2 + 1;
  res += max(min(R, n) - L + 1, 0);
  return res;
}
int LCA(int x, int y) {
  while (x != y)
    if (x > y)
      x >>= 1;
    else
      y >>= 1;
  return x;
}
map<int, int> mp;
int num[2333];
int getid(int x) {
  if (!mp[x]) mp[x] = (int)mp.size();
  return mp[x];
}
void Addedge(int u, int v) {
  edge[u].push_back(v);
  edge[v].push_back(u);
}
void pre(int u, int f) {
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == f) continue;
    num[u] -= num[v];
    pre(v, u);
  }
}
bool vis[2333];
void dfs(int u, int &tot) {
  tot = (tot + num[u]) % Mod;
  vis[u] = 1;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (!vis[v]) dfs(v, tot);
  }
  vis[u] = false;
}
int main() {
  n = read(), m = read();
  maxdeep = deep(n);
  getid(1);
  for (register int i = (0); i < (m); ++i) {
    u[i] = read(), v[i] = read();
    int t = u[i];
    while (t) getid(t), t >>= 1;
    t = v[i];
    while (t) getid(t), t >>= 1;
  }
  map<int, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    int u = it->first, id = it->second;
    if (u > 1) {
      Addedge(getid(u), getid(u >> 1));
    }
    num[id] = size(u);
  }
  pre(1, 1);
  for (register int i = (0); i < (m); ++i) Addedge(getid(u[i]), getid(v[i]));
  int res = 0;
  for (int i = 1; i <= (int)mp.size(); i++) {
    int tot = 0;
    dfs(i, tot);
    res = (res + 1ll * tot * num[i] % Mod) % Mod;
  }
  printf("%d\n", res);
  return 0;
}
