#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
const int N = 1005;
vector<int> e[N];
int vis[N], sz[N];
int n, m, ans, nd;
int x[10], y[10];
map<int, int> mp;
int getid(int x) { return mp[x] ? mp[x] : mp[x] = ++nd; }
int F(int x) {
  int l = x, r = x, ans = 0;
  for (; l <= n; l = l * 2, r = r * 2 + 1) ans += min(r, n) - l + 1;
  return ans;
}
void init(int x, int fa) {
  for (auto i : e[x])
    if (i != fa) {
      sz[x] -= sz[i];
      init(i, x);
    }
}
int FF(int x) {
  int ans = sz[x];
  vis[x] = 1;
  for (auto i : e[x])
    if (!vis[i]) ans = (ans + FF(i)) % mo;
  vis[x] = 0;
  return ans;
}
void add(int x, int y) {
  e[x].push_back(y);
  e[y].push_back(x);
}
int main() {
  scanf("%d%d", &n, &m);
  getid(1);
  for (int i = (int)(1); i <= (int)(m); i++) {
    scanf("%d%d", &x[i], &y[i]);
    for (int p = x[i]; p; getid(p), p /= 2)
      ;
    for (int p = y[i]; p; getid(p), p /= 2)
      ;
  }
  for (auto i : mp) {
    if (i.first > 1) add(i.second, getid(i.first / 2));
    sz[i.second] = F(i.first);
  }
  init(1, 0);
  for (int i = (int)(1); i <= (int)(m); i++) add(getid(x[i]), getid(y[i]));
  for (int i = (int)(1); i <= (int)(nd); i++)
    ans = (ans + 1ll * sz[i] * FF(i)) % mo;
  printf("%d\n", ans);
}
