#include <bits/stdc++.h>
using namespace std;
vector<int> adj[300];
int u[300], v[300], sz[300];
bool col[300];
int tree_height;
vector<pair<int, int> > nodes;
map<int, int> m;
int cal_depth(int n) {
  int d = 0;
  while (n) {
    d++;
    n = n >> 1;
  }
  return d;
}
int cal_size(int u, int n) {
  int hu = tree_height - cal_depth(u) + 1;
  int hn = u;
  for (int i = (1); i < (hu); ++i) {
    hn = (hn << 1) | 1;
  }
  return ((1 << hu) - 1) - min(max(0, hn - n), 1 << (hu - 1));
}
int get_id(int n) {
  if (!m[n]) {
    m[n] = m.size();
    nodes.push_back(make_pair(n, m[n]));
  }
  return m[n];
}
void make_adj(int u, int v) {
  if (!u || !v) return;
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void pre_size(int n, int p) {
  for (int i = (0); i < (adj[n].size()); ++i) {
    if (p == adj[n][i]) continue;
    sz[n] -= sz[adj[n][i]];
    pre_size(adj[n][i], n);
  }
}
long long dfs(int cn) {
  long long sum = sz[cn];
  col[cn] = true;
  for (int i = (0); i < (adj[cn].size()); ++i) {
    if (!col[adj[cn][i]]) sum += dfs(adj[cn][i]);
    sum %= 1000000007;
  }
  col[cn] = false;
  return sum;
}
int main() {
  int n, ee;
  scanf("%d%d", &n, &ee);
  tree_height = cal_depth(n);
  get_id(1);
  for (int i = (0); i < (ee); ++i) {
    scanf("%d%d", &u[i], &v[i]);
    int t = u[i];
    while (t) {
      get_id(t);
      t = t >> 1;
    }
    t = v[i];
    while (t) {
      get_id(t);
      t = t >> 1;
    }
  }
  for (int i = (0); i < (nodes.size()); ++i) {
    pair<int, int> t = nodes[i];
    int u = t.first, id = t.second;
    make_adj(m[u], m[u >> 1]);
    sz[id] = cal_size(u, n);
  }
  pre_size(1, 0);
  for (int i = (0); i < (ee); ++i) {
    make_adj(get_id(u[i]), get_id(v[i]));
  }
  long long res = 0;
  for (int i = (0); i < (nodes.size()); ++i) {
    pair<int, int> t = nodes[i];
    int u = t.first, id = t.second;
    long long tres = dfs(id);
    res += tres * sz[id];
    res %= 1000000007;
    col[id] = false;
  }
  cout << res << endl;
  return 0;
}
