#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int MAXM = MAXN * MAXN;
const int MOD = 1e9 + 7;
int _w;
int n, m, s[4], t[4], ans;
map<int, int> id;
int nid, w[MAXN];
namespace G {
int head[MAXN], nxt[MAXM], to[MAXM], m;
void init() { memset(head, -1, sizeof head); }
void adde(int u, int v) {
  to[m] = v, nxt[m] = head[u], head[u] = m++;
  to[m] = u, nxt[m] = head[v], head[v] = m++;
}
}  // namespace G
void mark(int u) {
  while (u && !id.count(u)) id[u] = ++nid, u >>= 1;
}
int calc(int u) {
  int l = u, r = u, k = 1;
  while (1) {
    if (l > n) return (1 << (k - 1)) - 1;
    if (r > n) return (1 << k) - 1 - (r - n);
    l <<= 1, r = (r << 1) | 1, ++k;
  }
  return -1;
}
void build(int u) {
  w[id[u]] = 1;
  int lc = u << 1, rc = lc | 1;
  if (lc <= n) {
    if (id.count(lc)) {
      G::adde(id[u], id[lc]);
      build(lc);
    } else {
      id[lc] = ++nid;
      G::adde(id[u], id[lc]);
      w[id[lc]] = calc(lc);
    }
  }
  if (rc <= n) {
    if (id.count(rc)) {
      G::adde(id[u], id[rc]);
      build(rc);
    } else {
      id[rc] = ++nid;
      G::adde(id[u], id[rc]);
      w[id[rc]] = calc(rc);
    }
  }
}
void prelude() {
  for (int i = 0; i < m; ++i) mark(s[i]), mark(t[i]);
  G::init();
  build(1);
  for (int i = 0; i < m; ++i) G::adde(id[s[i]], id[t[i]]);
}
int vis[MAXN];
void dfs(int u, int ws) {
  using namespace G;
  vis[u] = 1;
  ans = int(ans + (long long)ws * w[u] % MOD) % MOD;
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    if (vis[v]) continue;
    dfs(v, ws);
  }
  vis[u] = 0;
}
void solve() {
  for (int i = 1; i <= nid; ++i) {
    dfs(i, w[i]);
  }
  printf("%d\n", ans);
}
int main() {
  _w = scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) _w = scanf("%d%d", s + i, t + i);
  if (!m)
    printf("%lld\n", (long long)n * n % MOD);
  else
    prelude(), solve();
  return 0;
}
