#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, nxt;
} e[2050];
int ecnt;
int n, m;
int totdep;
int pw[2050];
map<int, int> head;
map<int, bool> has_fa;
map<int, int> sz;
map<int, bool> vis;
void adde(int u, int v) {
  e[++ecnt].v = v;
  e[ecnt].nxt = head[u];
  head[u] = ecnt;
}
int getdep(int pos) { return pos == 0 ? 0 : getdep(pos / 2) + 1; }
int getsz(int pos) {
  int curdep = getdep(pos);
  int tmp = curdep;
  int lc = pos, rc = pos;
  while (curdep < totdep) {
    curdep++;
    lc = lc << 1;
    rc = rc << 1 | 1;
  }
  if (n < lc)
    return pw[totdep - tmp - 1];
  else if (n > rc)
    return pw[totdep - tmp];
  else
    return pw[totdep - tmp - 1] + n - lc + 1;
}
int us[2050], vs[2050];
int seq[2050], scnt;
long long ans;
const int mod = 1000000007;
void mark(int pos) {
  while (pos / 2) {
    if (has_fa[pos]) return;
    has_fa[pos] = 1;
    seq[++scnt] = pos;
    pos = pos / 2;
  }
}
void dfs_sz(int pos) {
  sz[pos] = getsz(pos);
  if (has_fa[pos << 1]) dfs_sz(pos << 1), sz[pos] -= getsz(pos << 1);
  if (has_fa[pos << 1 | 1])
    dfs_sz(pos << 1 | 1), sz[pos] -= getsz(pos << 1 | 1);
}
int cur;
void dfs_solv(int pos) {
  vis[pos] = 1;
  ans += 1ll * cur * sz[pos] % mod;
  ans %= mod;
  if (!vis[pos << 1] && has_fa[pos << 1]) dfs_solv(pos << 1);
  if (!vis[pos << 1 | 1] && has_fa[pos << 1 | 1]) dfs_solv(pos << 1 | 1);
  if (!vis[pos >> 1] && (pos >> 1)) dfs_solv(pos >> 1);
  for (int i = head[pos]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (!vis[v]) dfs_solv(v);
  }
  vis[pos] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("%lld\n", n * 1ll * n % mod);
    return 0;
  }
  seq[++scnt] = 1;
  totdep = getdep(n);
  pw[0] = 1;
  for (int i = 1; i <= 1000; ++i) pw[i] = pw[i - 1] * 2 + 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &us[i], &vs[i]);
    mark(us[i]);
    mark(vs[i]);
    adde(us[i], vs[i]);
    adde(vs[i], us[i]);
  }
  dfs_sz(1);
  for (int i = 1; i <= scnt; ++i) {
    cur = sz[seq[i]];
    dfs_solv(seq[i]);
  }
  printf("%lld\n", ans);
}
