#include <bits/stdc++.h>
using namespace std;
namespace TYC {
const int N = 10010;
const int p = 1e9 + 7;
int node, n, m, Head[N], size[N];
struct edge {
  int to, next;
} E[N << 1];
map<int, int> id;
inline void add(const int u, const int v) {
  static int cnt;
  E[++cnt] = (edge){v, Head[u]};
  Head[u] = cnt;
  E[++cnt] = (edge){u, Head[v]};
  Head[v] = cnt;
}
inline int calc(const int x) {
  int l = x, r = x, tot = 0;
  while (l <= n) {
    tot += (r <= n ? r : n) - l + 1;
    l <<= 1, r = r << 1 | 1;
  }
  return tot;
}
void pre(const int u, const int f) {
  for (int i = Head[u]; i; i = E[i].next) {
    int v = E[i].to;
    if (v == f) continue;
    size[u] -= size[v];
    pre(v, u);
  }
}
void dfs(const int u, int &num) {
  static int vis[N];
  num = (num + size[u]) % p;
  vis[u] = 1;
  for (int i = Head[u]; i; i = E[i].next)
    if (!vis[E[i].to]) dfs(E[i].to, num);
  vis[u] = 0;
}
void work() {
  scanf("%d%d", &n, &m);
  if (!m) {
    printf("%lld\n", (long long)n * n % p);
    return;
  }
  id[1] = ++node;
  static int u[N], v[N];
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    for (int t = u[i]; t; t >>= 1)
      if (!id.count(t)) id[t] = ++node;
    for (int t = v[i]; t; t >>= 1)
      if (!id.count(t)) id[t] = ++node;
  }
  for (map<int, int>::iterator it = id.begin(); it != id.end(); it++) {
    int x = it->first;
    if (x != 1) add(it->second, id[x >> 1]);
    size[it->second] = calc(x);
  }
  pre(1, 0);
  for (int i = 1; i <= m; i++) add(id[u[i]], id[v[i]]);
  long long ans = 0;
  for (int i = 1; i <= node; i++) {
    int num = 0;
    dfs(i, num);
    ans = (ans + (long long)num * size[i] % p) % p;
  }
  printf("%lld\n", ans);
}
}  // namespace TYC
int main() {
  TYC::work();
  return 0;
}
