#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
map<int, int> sz;
set<int> vis;
map<int, vector<int> > g;
int n, m, ans;
int get_sz(int t) {
  int ret = 0;
  for (int i = 0; (t << i) <= n; ++i)
    ret += min(((t + 1) << i), n + 1) - (t << i);
  return ret;
}
void ins_node(int x) {
  for (; x; x /= 2) sz[x] = 0;
}
void dfs(int x, int y) {
  vis.insert(x);
  ans = (ans + (long long)y * sz[x]) % mod;
  for (int i : g[x])
    if (!vis.count(i)) dfs(i, y);
  vis.erase(x);
}
int main() {
  ins_node(1);
  for (cin >> n >> m; m-- > 0;) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
    ins_node(x);
    ins_node(y);
  }
  for (auto i : sz) {
    int u = i.first, v = u / 2;
    int res = get_sz(u);
    sz[u] += res;
    if (v) {
      sz[v] -= res;
      g[u].push_back(v);
      g[v].push_back(u);
    }
  }
  for (auto i : sz) dfs(i.first, i.second);
  cout << ans << '\n';
  return 0;
}
