#include <bits/stdc++.h>
using namespace std;
set<int> p;
map<int, int> mp;
int n, m;
int x[5], y[5];
int dp[250];
const int mod = 1e9 + 7;
vector<int> G[250];
void add(int x) {
  while (x) p.insert(x), x /= 2;
}
int cal(int x) {
  int ans = 0, t = 1;
  while (x <= n) {
    ans += min(n - x + 1, t);
    t <<= 1;
    x <<= 1;
  }
  return ans;
}
bool vis[250];
long long tmp;
void dfs(int u) {
  vis[u] = 1;
  tmp += dp[u];
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (vis[v]) continue;
    dfs(v);
  }
  vis[u] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("%I64d\n", 1ll * n * n % mod);
    return 0;
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    add(x[i]);
    add(y[i]);
  }
  int cnt = 0;
  for (set<int>::iterator it = p.begin(); it != p.end(); ++it) mp[*it] = ++cnt;
  for (set<int>::iterator it = p.begin(); it != p.end(); ++it) {
    int u = *it;
    dp[mp[u]] = 1;
    if (!p.count(u << 1))
      dp[mp[u]] += cal(u << 1);
    else
      G[mp[u]].push_back(mp[u << 1]), G[mp[u << 1]].push_back(mp[u]);
    if (!p.count(u << 1 | 1))
      dp[mp[u]] += cal(u << 1 | 1);
    else
      G[mp[u]].push_back(mp[u << 1 | 1]), G[mp[u << 1 | 1]].push_back(mp[u]);
  }
  for (int i = 1; i <= m; ++i) {
    G[mp[x[i]]].push_back(mp[y[i]]);
    G[mp[y[i]]].push_back(mp[x[i]]);
  }
  long long ans = 0;
  for (int i = 1; i <= cnt; ++i) {
    tmp = 0;
    dfs(i);
    ans = (ans + dp[i] * tmp % mod) % mod;
  }
  printf("%I64d\n", ans);
  return 0;
}
