#include <bits/stdc++.h>
using namespace std;
bool vis[1010];
vector<int> a[1010];
int u[5], v[5], s[1010];
const int mod = 1e9 + 7;
int n = 0, m = 0;
long long res = 0;
map<int, int> g;
int getId(int x) {
  if (g.find(x) == g.end()) {
    int id = g.size();
    g[x] = id;
  }
  return g[x];
}
void genId(int x) {
  for (; x > 0; x >>= 1) {
    getId(x);
  }
}
int cal(int x) {
  int l = x, r = x, cnt = 0;
  for (; l <= n; l <<= 1, r = 2 * r + 1) {
    cnt += min(r, n) - l + 1;
  }
  return cnt;
}
void dfs(int x, long long b) {
  vis[x] = true;
  res = (res + b * s[x]) % mod;
  for (auto nxt : a[x]) {
    if (!vis[nxt]) {
      dfs(nxt, b);
    }
  }
  vis[x] = false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &u[i], &v[i]);
    genId(u[i]);
    genId(v[i]);
    a[g[u[i]]].push_back(g[v[i]]);
    a[g[v[i]]].push_back(g[u[i]]);
  }
  genId(1);
  for (auto p : g) {
    s[p.second] = cal(p.first);
    if (g.find(p.first * 2) != g.end()) {
      s[p.second] -= cal(p.first * 2);
    }
    if (g.find(p.first * 2 + 1) != g.end()) {
      s[p.second] -= cal(p.first * 2 + 1);
    }
    if (p.first > 1) {
      a[g[p.first / 2]].push_back(g[p.first]);
      a[g[p.first]].push_back(g[p.first / 2]);
    }
  }
  for (int i = 0; i < g.size(); ++i) {
    dfs(i, s[i]);
  }
  printf("%I64d", res);
  return 0;
}
