#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
int n, m;
pair<int, int> gg[N];
int x[10], y[10];
int sz[1000];
vector<int> aa[1000];
bool vis[1000];
map<int, int> g, id;
void gao(int x, set<int>& s) {
  while (x > 0) {
    s.insert(x);
    x /= 2;
  }
}
void dfs(int x, long long b, long long& ans) {
  vis[x] = true;
  ans += b * sz[x];
  ans %= mod;
  for (int i : aa[x]) {
    if (!vis[i]) {
      dfs(i, b, ans);
    }
  }
  vis[x] = false;
}
int calc(int x) {
  int left = x;
  int right = x;
  int re = 0;
  while (true) {
    if (left > n) {
      return re;
    }
    re += min(right, n) - left + 1;
    right = right * 2 + 1;
    left = left * 2;
  }
  return re;
}
int brute() {
  set<int> s;
  long long ans = 0;
  memset(x, 0, sizeof(x));
  memset(y, 0, sizeof(y));
  memset(sz, 0, sizeof(sz));
  memset(aa, 0, sizeof(aa));
  memset(vis, 0, sizeof(vis));
  g.clear();
  id.clear();
  for (int i = 0; i < m; i++) {
    x[i] = gg[i].first;
    y[i] = gg[i].second;
    gao(x[i], s);
    gao(y[i], s);
  }
  s.insert(1);
  for (int i : s) {
    if (s.find(2 * i) == s.end() && s.find(2 * i + 1) == s.end()) {
      g[i] = calc(i);
    } else {
      g[i] = 1;
      if (2 * i <= n && s.find(2 * i) == s.end()) {
        g[2 * i] = calc(2 * i);
      }
      if (2 * i + 1 <= n && s.find(2 * i + 1) == s.end()) {
        g[2 * i + 1] = calc(2 * i + 1);
      }
    }
  }
  for (pair<int, int> sth : g) {
    int i = sth.first;
    int u = (int)id.size();
    id[i] = u;
    sz[u] = g[i];
  }
  int nn = (int)g.size();
  for (pair<int, int> sth : id) {
    int i = sth.first;
    if (i == 1) {
      continue;
    }
    int child = id[i];
    int father = id[i / 2];
    aa[child].push_back(father);
    aa[father].push_back(child);
  }
  for (int i = 0; i < m; i++) {
    int first = id[x[i]];
    int second = id[y[i]];
    aa[first].push_back(second);
    aa[second].push_back(first);
  }
  for (int i = 0; i < nn; i++) {
    dfs(i, sz[i], ans);
  }
  return (int)ans;
}
int levels = 1;
int le, re;
int lca(int a, int b) {
  set<int> s;
  while (a > 0) {
    s.insert(a);
    a /= 2;
  }
  while (b > 0) {
    if (s.count(b)) {
      return b;
    }
    b /= 2;
  }
  return 1;
}
int get(int v) {
  int l = v;
  int r = v;
  int ans = 0;
  while (r < (1 << (levels - 1))) {
    ans += r - l + 1;
    r = r * 2 + 1;
    l = l * 2;
  }
  r = min(r, re);
  l = max(le, l);
  if (l <= r) ans += r - l + 1;
  return ans;
}
vector<int> paths(int a, int b) {
  vector<int> A, B;
  int p = lca(a, b);
  while (a != p) {
    A.push_back(a);
    a /= 2;
  }
  while (b != p) {
    B.push_back(b);
    b /= 2;
  }
  reverse(B.begin(), B.end());
  A.push_back(p);
  for (auto it : B) {
    A.push_back(it);
  }
  return A;
}
void upd(int& a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int gdfs(int v, int p, set<int>& marked, set<int>& path) {
  if (v < 1 || v > n) return 0;
  if (path.count(v)) {
    return 0;
  }
  if (!marked.count(v)) {
    return get(v);
  }
  int ans = 1;
  if (v / 2 != p) upd(ans, gdfs(v / 2, v, marked, path));
  if (v + v != p) upd(ans, gdfs(v + v, v, marked, path));
  if (v + v + 1 != p) {
    upd(ans, gdfs(v + v + 1, v, marked, path));
  }
  return ans;
}
int fnd(vector<pair<int, int> > cur) {
  vector<int> line;
  for (int i = 0; i < (int)cur.size(); ++i) {
    line.push_back(cur[i].first);
    line.push_back(cur[i].second);
  }
  for (int i = 0; i < (int)line.size(); ++i) {
    for (int j = 0; j < (int)line.size(); ++j) {
      if (abs(i - j) > 1) {
        if (line[i] == line[j]) return 0;
      }
    }
  }
  set<int> path;
  for (int i = 0; i < (int)cur.size(); ++i) {
    path.insert(cur[i].first);
    if (path.count(cur[i].second)) return 0;
    path.insert(cur[i].second);
    if (i + 1 < (int)cur.size()) {
      vector<int> path1 = paths(cur[i].second, cur[i + 1].first);
      for (auto it : path1) {
        if (it != cur[i].second && path.count(it)) {
          return 0;
        }
        path.insert(it);
      }
    }
  }
  int a = line[0];
  int b = line.back();
  int p = lca(a, b);
  bool both = 1;
  vector<int> A;
  vector<int> B;
  while (a != (p / 2)) {
    if (path.count(a)) {
      if (a != line[0] && a != line.back()) {
        both = 0;
        break;
      }
    }
    A.push_back(a);
    a /= 2;
  }
  while (b != (p / 2)) {
    if (path.count(b)) {
      if (b != line[0] && b != line.back()) {
        both = 0;
        break;
      }
    }
    B.push_back(b);
    b /= 2;
  }
  a = line[0];
  b = line.back();
  set<int> marked;
  for (auto it : path) {
    int cur = it;
    while (cur > 0) {
      marked.insert(cur);
      cur /= 2;
    }
  }
  if (!both) {
    path.erase(a);
    int cnt1 = gdfs(a, -1, marked, path);
    path.insert(a);
    path.erase(b);
    int cnt2 = gdfs(b, -1, marked, path);
    path.insert(b);
    return (cnt1 * 1ll * cnt2) % mod;
  }
  B.pop_back();
  reverse(B.begin(), B.end());
  for (auto it : B) {
    A.push_back(it);
  }
  int ans = 0;
  int sz = (int)A.size();
  for (int i = 0; i + 1 < (int)A.size(); ++i) {
    if (A[i] == a) path.erase(a);
    if (i > 0) path.insert(A[i - 1]);
    if (i + 1 < sz) path.insert(A[i + 1]);
    int cnt1 = gdfs(A[i], -1, marked, path);
    if (i > 0) path.erase(A[i - 1]);
    if (i + 1 < sz) path.erase(A[i + 1]);
    path.insert(a);
    path.erase(b);
    path.insert(A[i]);
    int cnt2 = gdfs(b, -1, marked, path);
    int cur_ans = (cnt1 * 1ll * cnt2) % mod;
    upd(ans, cur_ans);
    path.erase(A[i]);
    path.insert(a);
    path.insert(b);
  }
  return ans;
}
int solve() {
  levels = 1;
  while ((1 << levels) - 1 < n) ++levels;
  int tmp = (1 << levels) - 1 - n;
  le = (1 << (levels - 1));
  re = (1 << levels) - 1 - tmp;
  int ans = (n * 1ll * n) % mod;
  vector<pair<vector<pair<int, int> >, int> > v;
  for (int msk = 1; msk < (1 << m); ++msk) {
    int cnt = 0;
    vector<pair<int, int> > cur1;
    for (int i = 0; i < m; ++i) {
      if ((1 << i) & msk) {
        cnt++;
        cur1.push_back(gg[i]);
      }
    }
    for (int new_msk = 0; new_msk < (1 << cnt); ++new_msk) {
      vector<pair<int, int> > cur;
      for (int i = 0; i < cnt; ++i) {
        if ((1 << i) & new_msk) {
          cur.push_back(cur1[i]);
        } else {
          cur.push_back({cur1[i].second, cur1[i].first});
        }
      }
      sort(cur.begin(), cur.end());
      do {
        v.push_back({cur, msk});
      } while (next_permutation(cur.begin(), cur.end()));
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (auto it : v) {
    upd(ans, fnd(it.first));
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> gg[i].first >> gg[i].second;
  }
  cout << solve() << endl;
  return 0;
}
