#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> inputExtraEdges;
int sizes[1000];
const int mod = 1e9 + 7;
map<int, int> g, id;
set<int> s;
vector<int> adj[1000];
long long ans;
bool visited[1000];
void insertInSet(int node) {
  while (node) {
    if (s.find(node) != s.end()) return;
    s.insert(node);
    node >>= 1;
  }
}
void dfs(int u, long long b) {
  visited[u] = true;
  ans += b * sizes[u];
  ans %= mod;
  for (int v : adj[u]) {
    if (!visited[v]) {
      dfs(v, b);
    }
  }
  visited[u] = false;
}
int calc(int node) {
  int leftChild = node;
  int rightChild = node;
  int returnValue = 0;
  while (true) {
    if (leftChild > n) {
      return returnValue;
    }
    returnValue += min(rightChild, n) - leftChild + 1;
    rightChild = (rightChild << 1) + 1;
    leftChild <<= 1;
  }
  return returnValue;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    inputExtraEdges.push_back(pair<int, int>(x, y));
    insertInSet(x);
    insertInSet(y);
  }
  insertInSet(1);
  for (int node : s) {
    int leftChild = node << 1;
    int rightChild = (node << 1) + 1;
    if (s.find(leftChild) == s.end() && s.find(rightChild) == s.end()) {
      g[node] = calc(node);
    } else {
      g[node] = 1;
      if (leftChild <= n && s.find(leftChild) == s.end()) {
        g[leftChild] = calc(leftChild);
      }
      if (rightChild <= n && s.find(rightChild) == s.end()) {
        g[rightChild] = calc(rightChild);
      }
    }
  }
  for (pair<int, int> pair : g) {
    int i = pair.first;
    int u = id.size();
    id[i] = u;
    sizes[u] = g[i];
  }
  assert(g.size() == id.size());
  int nn = g.size();
  for (pair<int, int> pair : id) {
    int i = pair.first;
    if (i == 1) {
      continue;
    }
    int child = id[i];
    int parent = id[i >> 1];
    adj[child].push_back(parent);
    adj[parent].push_back(child);
  }
  for (int i = 0; i < m; ++i) {
    int oneNode = inputExtraEdges[i].first;
    int anotherNode = inputExtraEdges[i].second;
    oneNode = id[oneNode];
    anotherNode = id[anotherNode];
    adj[oneNode].push_back(anotherNode);
    adj[anotherNode].push_back(oneNode);
  }
  for (int i = 0; i < nn; ++i) {
    dfs(i, sizes[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
