#include <bits/stdc++.h>
using namespace std;
const int N = 256, P = 1000000007;
using ll = long long;
int n, m, d, uu[N], vv[N];
ll num[N];
map<int, int> mp;
inline int ID(int x) { return mp[x] ? mp[x] : mp[x] = mp.size(); }
vector<int> v[N];
inline void add_edge(int uu, int vv) {
  v[uu].push_back(vv);
  v[vv].push_back(uu);
}
ll calc(int pos) {
  int tmp = pos, c = 0, ret;
  while (tmp) ++c, tmp >>= 1;
  ret = (1 << (d - c + 1)) - 1, tmp = c;
  while (tmp < d) ++tmp, pos = pos * 2 + 1;
  return ret - max(0, min(pos - n, 1 << (d - c)));
}
void dfs1(int pos, int fa) {
  for (auto &i : v[pos])
    if (i != fa) num[pos] -= num[i], dfs1(i, pos);
}
ll cur = 0;
bool vis[N];
void dfs2(int pos) {
  cur = (cur + num[pos]) % P;
  vis[pos] = 1;
  for (auto &i : v[pos])
    if (!vis[i]) dfs2(i);
  vis[pos] = 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  while ((1 << d) <= n) ++d;
  ID(1);
  for (int i = 1; i <= m; i++) {
    cin >> uu[i] >> vv[i];
    int t = uu[i];
    while (t) ID(t), t >>= 1;
    t = vv[i];
    while (t) ID(t), t >>= 1;
  }
  for (auto &i : mp) {
    int pos = i.first, id = i.second;
    if (pos > 1) add_edge(ID(pos), ID(pos >> 1));
    num[id] = calc(pos);
  }
  dfs1(1, 0);
  ll ans = 0;
  for (int i = 1; i <= m; i++) add_edge(ID(uu[i]), ID(vv[i]));
  for (int i = 1; i <= int(mp.size()); i++) {
    cur = 0;
    dfs2(i);
    ans = (ans + cur * num[i]) % P;
  }
  cout << ans << endl;
  return 0;
}
