#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007, N = 1010;
set<int> s;
map<int, int> g, id;
vector<int> a[N];
bool vis[N];
int n, m, x[9], y[9], sz[N];
long long ans;
void Insert(int x) {
  for (; x; x >>= 1) s.insert(x);
}
void dfs(int t, long long b) {
  vis[t] = true;
  (ans += b * sz[t]) %= mod;
  for (int i : a[t]) {
    if (!vis[i]) dfs(i, b);
  }
  vis[t] = false;
}
int calc(int x) {
  int L = x, R = x, ret = 0;
  while (L <= n) {
    ret += min(R, n) - L + 1;
    L <<= 1;
    R = R << 1 | 1;
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", x + i, y + i);
    Insert(x[i]), Insert(y[i]);
  }
  s.insert(1);
  for (int i : s) {
    if (s.find(i << 1) == s.end() && s.find(i << 1 | 1) == s.end()) {
      g[i] = calc(i);
    } else {
      g[i] = 1;
      if (i + i <= n && s.find(i << 1) == s.end()) {
        g[i << 1] = calc(i << 1);
      }
      if (i + i + 1 <= n && s.find(i + i + 1) == s.end()) {
        g[i + i + 1] = calc(i + i + 1);
      }
    }
  }
  for (pair<int, int> sth : g) {
    int i = sth.first, u = id.size();
    id[i] = u;
    sz[u] = g[i];
  }
  int cnt = g.size();
  for (pair<int, int> sth : id) {
    int i = sth.first;
    if (i == 1) continue;
    int son = id[i], f = id[i >> 1];
    a[son].push_back(f);
    a[f].push_back(son);
  }
  for (int i = 0; i < m; ++i) {
    int fst = id[x[i]], snd = id[y[i]];
    a[fst].push_back(snd);
    a[snd].push_back(fst);
  }
  for (int i = 0; i < cnt; ++i) dfs(i, sz[i]);
  cout << ans << '\n';
  return 0;
}
