#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int N, M;
long long ans;
map<int, int> weight;
set<int> vvv;
set<int> vst;
map<int, vector<int>> E;
bool has(long long p) {
  if (vvv.count(p)) return true;
  long long l = p * 2;
  long long r = p * 2 + 1;
  while (true) {
    if (vvv.upper_bound(l) == end(vvv)) break;
    if (vvv.upper_bound(r) != vvv.lower_bound(l)) return true;
    l = l * 2;
    r = r * 2 + 1;
  }
  return false;
}
int size(long long p) {
  int res = p <= N ? 1 : 0;
  int l = p * 2;
  int r = p * 2 + 1;
  while (l <= N) {
    res += min(r, N) - l + 1;
    l = l * 2;
    r = r * 2 + 1;
  }
  return res;
}
int calc(long long p) {
  int res = 1;
  queue<int> que;
  que.push(p);
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (int i = 0; i < (2); i++) {
      long long y = x * 2 + i;
      if (y > N) continue;
      if (has(y)) {
        if (!vvv.count(y)) que.push(y);
      } else {
        res += size(y);
      }
    }
  }
  return res;
}
vector<int> path;
void DFS(int u, long long w) {
  path.push_back(u);
  ans = (ans + w * weight[u]) % MOD;
  vst.insert(u);
  int e[] = {u * 2, u * 2 + 1, u / 2};
  for (int i = 0; i < (3); i++) {
    int v = e[i];
    if (v < 1 or v > N) continue;
    if (vst.count(v)) continue;
    if (!vvv.count(v)) continue;
    DFS(v, w);
  }
  for (auto v : E[u]) {
    if (v < 1 or v > N) continue;
    if (vst.count(v)) continue;
    DFS(v, w);
  }
  vst.erase(u);
  path.pop_back();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> N >> M;
  vvv.insert(1);
  for (int _ = 0; _ < (M); _++) {
    int u, v;
    cin >> u >> v;
    E[u].push_back(v);
    E[v].push_back(u);
    while (u) {
      vvv.insert(u);
      u /= 2;
    }
    while (v) {
      vvv.insert(v);
      v /= 2;
    }
  }
  for (auto it : vvv) {
    weight[it] = calc(it);
  }
  for (auto st : vvv) {
    DFS(st, weight[st]);
  }
  cout << ans << endl;
  return 0;
}
