#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 60;
const double Inf = 1e20;
const double eps = 1e-9;
void gmax(int &a, int b) { a = (a > b ? a : b); }
void gmin(int &a, int b) { a = (a < b ? a : b); }
const int P = 1e9 + 7;
const int maxn = 1000050;
int n, m, x[5], y[5], sz[maxn], Ans;
set<int> key;
map<int, int> id, g;
vector<int> adj[maxn];
bool vis[maxn];
int calc(int x) {
  int l = x, r = x, ret = 0;
  while (l <= n) {
    ret = (ret + min(r, n) - l + 1) % P;
    l = l << 1;
    r = r << 1 | 1;
  }
  return ret;
}
void dfs(int x, int t) {
  Ans = (Ans + 1ll * sz[x] * t) % P;
  vis[x] = true;
  for (auto p : adj[x])
    if (!vis[p]) dfs(p, t);
  vis[x] = false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    int t = x[i];
    while (t) {
      key.insert(t);
      t >>= 1;
    }
    t = y[i];
    while (t) {
      key.insert(t);
      t >>= 1;
    }
  }
  key.insert(1);
  for (auto p : key) {
    if (key.find(p << 1) == key.end() && key.find(p << 1 | 1) == key.end())
      g[p] = calc(p);
    else {
      g[p] = 1;
      if (key.find(p << 1) == key.end() && (p << 1) <= n)
        g[p << 1] = calc(p << 1);
      if (key.find(p << 1 | 1) == key.end() && (p << 1 | 1) <= n)
        g[p << 1 | 1] = calc(p << 1 | 1);
    }
  }
  for (pair<int, int> p : g) {
    id[p.first] = ((int)(id).size());
    sz[id[p.first]] = p.second;
  }
  for (pair<int, int> p : id)
    if (p.first != 1) {
      adj[id[p.first >> 1]].push_back(p.second);
      adj[p.second].push_back(id[p.first >> 1]);
    }
  for (int i = 1; i <= m; ++i)
    adj[id[x[i]]].push_back(id[y[i]]), adj[id[y[i]]].push_back(id[x[i]]);
  for (pair<int, int> p : id) dfs(p.second, sz[p.second]);
  printf("%d\n", Ans);
  return 0;
}
