#include <bits/stdc++.h>
using namespace std;
namespace INPUT {
const int L = 1 << 15;
char _buf[L], *S, *T, c;
char _gc() {
  if (S == T) {
    T = (S = _buf) + fread(_buf, 1, L, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
void readi(int &X) {
  bool flag;
  for (c = _gc(); (c < '0' || c > '9') && c != '-'; c = _gc())
    ;
  if (c == '-')
    flag = true, X = 0;
  else
    flag = false, X = c & 15;
  for (c = _gc(); c >= '0' && c <= '9'; X = X * 10 + (c & 15), c = _gc())
    ;
  if (flag) X = -X;
}
}  // namespace INPUT
using INPUT::readi;
const int Maxn = 2E3;
const int Mod = 1E9 + 7;
int N, M, K, tot;
struct E {
  int v, nxt;
} adj[Maxn];
int hed[Maxn], TE;
int deg[Maxn];
int s[Maxn << 4], n;
set<pair<int, int> > Set;
map<int, int> Map;
map<int, int>::iterator it;
int num[Maxn];
int Ans;
void addedge(int u, int v) {
  adj[++TE].v = v, adj[TE].nxt = hed[u], hed[u] = TE;
}
void Addedge(int u, int v, bool flag) {
  if (flag) {
    if (Set.find(pair<int, int>(u, v)) != Set.end()) return;
    Set.insert(pair<int, int>(u, v)), Set.insert(pair<int, int>(v, u));
  }
  if (Map.find(u) == Map.end()) Map[u] = ++tot;
  if (Map.find(v) == Map.end()) Map[v] = ++tot;
  int idu = Map[u], idv = Map[v];
  s[++n] = u, s[++n] = v;
  ++deg[idu], ++deg[idv];
  addedge(idu, idv), addedge(idv, idu);
}
void PrePare() {
  int tmp = N;
  while (tmp) ++K, tmp >>= 1;
}
int Calc(int X) {
  int tmp = X, k = 0;
  while (tmp) ++k, tmp >>= 1;
  if ((N >> K - k) > X) return (1 << K - k + 1) - 1;
  if ((N >> K - k) < X) return (1 << K - k) - 1;
  return ((1 << K - k) + N - (X << K - k));
}
void Add_Edge(int u, int v) {
  Addedge(u, v, false);
  while (u > 1) Addedge(u, u >> 1, true), u >>= 1;
  while (v > 1) Addedge(v, v >> 1, true), v >>= 1;
}
bool vis[Maxn];
void Dfs(int u, int rt) {
  vis[u] = true;
  for (int k = hed[u]; ~k; k = adj[k].nxt)
    if (!vis[adj[k].v]) Dfs(adj[k].v, rt);
  Ans = (Ans + (long long)num[rt] * num[u]) % Mod;
  vis[u] = false;
}
int main() {
  readi(N), readi(M), PrePare();
  if (M == 0) {
    printf("%d", (long long)N * N % Mod);
    return 0;
  }
  memset(hed, -1, sizeof(hed));
  for (int u, v, i = 1; i <= M; ++i) readi(u), readi(v), Add_Edge(u, v);
  sort(s + 1, s + n + 1), n = unique(s + 1, s + n + 1) - (s + 1);
  for (int i = 1; i <= n; ++i) {
    if ((s[i] << 1) <= N && Map.find(s[i] << 1) == Map.end())
      Map[s[i] << 1] = ++tot, ++deg[tot], ++deg[Map[s[i]]],
                  addedge(tot, Map[s[i]]), addedge(Map[s[i]], tot);
    if ((s[i] << 1 | 1) <= N && Map.find(s[i] << 1 | 1) == Map.end())
      Map[s[i] << 1 | 1] = ++tot, ++deg[tot], ++deg[Map[s[i]]],
                      addedge(tot, Map[s[i]]), addedge(Map[s[i]], tot);
  }
  for (it = Map.begin(); it != Map.end(); ++it)
    if (deg[(*it).second] > 1)
      num[(*it).second] = 1;
    else
      num[(*it).second] = Calc((*it).first);
  for (int i = 1; i <= tot; ++i) Dfs(i, i);
  printf("%d", Ans);
  return 0;
}
