#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9, maxn = 5e5 + 5, mod = 1e9 + 7;
long long x[maxn], y[maxn], sz[maxn], n, m;
set<long long> S;
unordered_map<long long, long long> cnt, id;
vector<long long> son[maxn];
long long gc(long long x) {
  long long ret = 0, j = 0;
  while (x <= n) {
    ret += min(x + (1 << j) - 1, n) - x + 1;
    x <<= 1;
    ++j;
    ret %= mod;
  }
  return ret;
}
void dfs(long long x) {
  if (S.count(x)) {
    cnt[x] = 1;
    if ((x << 1) <= n) dfs(x << 1);
    if ((x << 1 | 1) <= n) dfs(x << 1 | 1);
  } else
    cnt[x] = gc(x);
}
long long vis[maxn];
long long dfs2(long long x) {
  vis[x] = 1;
  long long ret = sz[x];
  for (auto js : son[x])
    if (!vis[js]) {
      (ret += dfs2(js)) %= mod;
    }
  vis[x] = 0;
  return ret;
}
signed main() {
  scanf("%lld%lld", &n, &m);
  if (m == 0) return printf("%lld\n", 1ll * n * n % mod), 0;
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    long long tmp = x[i];
    while (tmp) {
      S.insert(tmp);
      tmp >>= 1;
    }
    tmp = y[i];
    while (tmp) {
      S.insert(tmp);
      tmp >>= 1;
    }
  }
  S.insert(1);
  dfs(1);
  long long idc = 0;
  for (auto i : cnt) id[i.first] = ++idc;
  for (auto i : cnt) {
    long long u = id[i.first];
    sz[u] = i.second;
    for (long long j = 0; j <= 1; j++) {
      long long v = i.first << 1 | j;
      if (!cnt.count(v)) continue;
      v = id[v];
      son[u].push_back(v);
      son[v].push_back(u);
    }
  }
  for (long long i = 1; i <= m; i++)
    son[id[x[i]]].push_back(id[y[i]]), son[id[y[i]]].push_back(id[x[i]]);
  long long ans = 0;
  for (long long i = 1; i <= idc; i++)
    ans = (ans + 1ll * sz[i] * sz[i] % mod) % mod;
  for (long long i = 1; i <= idc; i++) {
    vis[i] = 1;
    long long cura = 0;
    for (auto js : son[i]) {
      cura = (cura + dfs2(js)) % mod;
    }
    ans = (ans + 1ll * cura * sz[i] % mod) % mod;
    vis[i] = 0;
  }
  printf("%lld\n", ans);
  return 0;
}
