#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
vector<pair<int, int> > mp[335];
vector<int> vp;
vector<pair<int, int> > es;
int N, eid;
map<int, int> id;
void add(int u, int v) {
  while (u != v) {
    if (u < v) swap(u, v);
    vp.push_back(u);
    u >>= 1;
  }
  while (u >= 1) {
    vp.push_back(u);
    u >>= 1;
  }
}
int getChilds(int id) {
  int ans = 0;
  int l = id, r = id;
  while (r <= n) {
    ans += r - l + 1;
    l <<= 1;
    r = r << 1 | 1;
  }
  if (l <= n) ans += n - l + 1;
  return ans;
}
int sz[335];
void addE(int u, int v) {
  eid++;
  mp[u].push_back({v, eid});
  mp[v].push_back({u, eid});
}
bool vis[335];
void minusChild(int x, int pa) {
  vis[x] = 1;
  for (auto cp : mp[x])
    if (cp.first != pa) {
      if (!vis[cp.first]) {
        sz[x] -= sz[cp.first];
        minusChild(cp.first, x);
      }
    }
}
int tot;
void dfs(int x, int pa) {
  addmod(tot, sz[x]);
  vis[x] = 1;
  for (auto cp : mp[x])
    if (cp.first != pa) {
      if (!vis[cp.first]) dfs(cp.first, x);
    }
  vis[x] = 0;
}
void fmain(int tid) {
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("%lld\n", (long long)n * n % 1000000007);
    return;
  }
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    es.push_back({u, v});
  }
  sort(vp.begin(), vp.end());
  N = unique(vp.begin(), vp.end()) - vp.begin();
  for (int(i) = 0; (i) < (int)(N); (i)++) id[vp[i]] = i;
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    sz[i] = getChilds(vp[i]);
  }
  for (int(i) = 0; (i) < (int)(N); (i)++)
    if (vp[i] != 1) {
      int u = id[vp[i]], v = id[vp[i] >> 1];
      addE(u, v);
    }
  minusChild(0, -1);
  for (auto p : es) addE(id[p.first], id[p.second]);
  memset(vis, 0, sizeof vis);
  int ans = 0;
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    tot = 0;
    dfs(i, -1);
    addmod(ans, (long long)tot * sz[i] % 1000000007);
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
