#include <bits/stdc++.h>
using namespace std;
set<int> st;
int n, m, s[5], e[5];
inline int getdep(int x) {
  for (int ret = 1;; ret++) {
    if (x < (1 << ret)) return ret;
  }
}
inline void getpath(int x) {
  while (x) {
    st.insert(x);
    x >>= 1;
  }
}
vector<pair<int, int> > v[10000];
void addedge(int s, int e, int w) {
  v[s].push_back(make_pair(e, w));
  v[e].push_back(make_pair(s, w));
}
const int mod = 1000000007;
inline int add(int a, int b) {
  if ((a += b) >= mod) a -= mod;
  return a;
}
inline int mult(int a, int b) {
  long long t = 1ll * a * b;
  if (t >= mod) t %= mod;
  return t;
}
int nodecnt = 0, siz[10000];
int ans = 0;
bool vis[10000];
inline int getsize(long long p) {
  long long ret = 0, csiz = 1, L = p;
  while (1) {
    if (p >= n) {
      if (n >= L) ret += (n - L + 1);
      return ret;
    }
    ret += csiz;
    csiz <<= 1;
    p = (p << 1) | 1;
    L = (L << 1);
  }
  return 0;
}
unordered_map<int, int> mp;
int buildtree(int p) {
  int cur = ++nodecnt;
  mp[p] = cur;
  if (!st.count(p)) {
    siz[cur] = getsize(p);
    return cur;
  }
  siz[cur] = 1;
  if ((p << 1) <= n) addedge(cur, buildtree(p << 1), 0);
  if (((p << 1) | 1) <= n) addedge(cur, buildtree((p << 1) | 1), 0);
  return cur;
}
void dfs(int np, bool haspass, int Sst) {
  if (haspass) ans = add(ans, mult(Sst, siz[np]));
  vis[np] = 1;
  for (auto &x : v[np]) {
    if (!vis[x.first]) dfs(x.first, haspass | x.second, Sst);
  }
  vis[np] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s[i], &e[i]);
    getpath(s[i]);
    getpath(e[i]);
  }
  ans = mult(n, n);
  buildtree(1);
  for (int i = 1; i <= m; i++) addedge(mp[s[i]], mp[e[i]], 1);
  for (int i = 1; i <= nodecnt; i++) dfs(i, 0, siz[i]);
  printf("%d\n", ans);
  return 0;
}
