#include <bits/stdc++.h>
using namespace std;
void Freopen() {
  freopen(
      "title"
      ".in",
      "r", stdin);
  freopen(
      "title"
      ".out",
      "w", stdout);
}
int read() {
  int g = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    g = g * 10 + ch - '0';
    ch = getchar();
  }
  return g * f;
}
const int N = 250;
const int mod = 1e9 + 7;
vector<int> G[N];
int tot, vis[N], size[N], fid[N], n, m, ans;
unordered_map<int, int> id;
int Get(int x) {
  if (id[x]) return id[x];
  return tot++, fid[tot] = x, id[x] = tot;
}
void Climb(int x) {
  if (!x) return;
  Get(x);
  Climb(x / 2);
  return;
}
void Add(int x, int y) {
  G[x].push_back(y);
  G[y].push_back(x);
}
void Size(int L, int R, int &siz) {
  if (n < L) return;
  if (n < R) return siz += n - L + 1, void();
  siz += R - L + 1;
  Size(L << 1, R << 1 | 1, siz);
}
void Solve(int x) {
  if (id[x << 1]) size[id[x]] -= size[id[x << 1]], Solve(x << 1);
  if (id[x << 1 | 1]) size[id[x]] -= size[id[x << 1 | 1]], Solve(x << 1 | 1);
}
void Dfs(int x, int anc) {
  ans = (1ll * size[anc] * size[x] % mod + ans) % mod;
  for (auto y : G[x])
    if (!vis[y]) vis[y] = 1, Dfs(y, anc), vis[y] = 0;
}
signed main() {
  n = read(), m = read();
  Get(1);
  for (int i = (1); i <= (m); i++) {
    int x = read(), y = read();
    Climb(x), Climb(y);
    Add(Get(x), Get(y));
  }
  for (int i = (1); i <= (tot); i++)
    if (fid[i] > 1) Add(i, id[fid[i] / 2]);
  for (int i = (1); i <= (tot); i++) Size(fid[i], fid[i], size[i]);
  Solve(1);
  for (int i = (1); i <= (tot); i++) vis[i] = 1, Dfs(i, i), vis[i] = 0;
  return cout << ans, signed();
}
