#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int n;
set<int> st;
int lca(int a, int b) {
  if (__builtin_clz(a) > __builtin_clz(b)) swap(a, b);
  while (__builtin_clz(a) < __builtin_clz(b)) a >>= 1;
  while (a != b) a >>= 1, b >>= 1;
  return a;
}
inline bool papa(int a, int b) {
  if (b <= a) return 0;
  int dif = __builtin_clz(a) - __builtin_clz(b);
  return a == (b >> dif);
}
int Size(int a) {
  int x = 1, ans = 0;
  while (a <= n) {
    ans += min(x, n - a + 1);
    x <<= 1, a <<= 1;
  }
  return ans;
}
int Size(int a, set<int>& s) {
  int ans = Size(a);
  vector<int> vv;
  for (int x : s) {
    if (x < a) continue;
    bool bl1 = papa(a, x), bl2 = 0;
    for (int y : vv) bl2 |= papa(y, x);
    if (bl1 && !bl2) vv.push_back(x), ans -= Size(x);
  }
  return ans;
}
int solve(int a, int b) {
  set<int> st2;
  int ans = 0;
  for (int A = a; A > 0; A >>= 1) {
    st2 = st;
    for (int B = b; B > 0; B >>= 1) {
      ans = (1ll * ans + 1ll * Size(A, st2) * Size(B, st2)) % mod;
      if (st2.count(B >> 1)) break;
      st2.insert(B >> 1);
    }
    if (st.count(A >> 1)) break;
    st.insert(A >> 1);
  }
  return ans;
}
int CNT = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int m;
  cin >> n >> m;
  vector<pair<int, int> > vv(m), vv2;
  for (int i = 0; i < m; i++) {
    cin >> vv[i].first >> vv[i].second;
  }
  long long ans = (1ll * n * n) % mod;
  for (int msk = 1; msk < (1 << m); msk++) {
    vv2.clear();
    for (int i = 0; i < m; i++) {
      if ((((msk) >> (i)) & 1)) vv2.push_back(vv[i]);
    }
    vector<int> perm(int((vv2).size()));
    for (int i = 0; i < int((vv2).size()); i++) perm[i] = i;
    do {
      vector<pair<int, int> > vv3(int((vv2).size()));
      for (int i = 0; i < int((vv2).size()); i++) vv3[i] = vv2[perm[i]];
      int lst = -1, frst = -1;
      for (int msk2 = 0; msk2 < (1 << int((vv2).size())); msk2++) {
        st.clear();
        frst = vv3[0].first, lst = vv3[0].second;
        if ((((msk2) >> (0)) & 1)) swap(frst, lst);
        st.insert(frst);
        for (int i = 1; i < int((vv3).size()); i++) {
          pair<int, int> p = vv3[i];
          if ((((msk2) >> (i)) & 1)) swap(p.first, p.second);
          int A = lst, B = p.first, C = lca(A, B);
          while (A != C) {
            if (st.count(A)) goto Hell;
            st.insert(A);
            A >>= 1;
          }
          while (B != C) {
            if (st.count(B)) goto Hell;
            st.insert(B);
            B >>= 1;
          }
          if (st.count(C)) goto Hell;
          st.insert(C);
          lst = p.second;
        }
        if (st.count(lst)) goto Hell;
        st.insert(lst);
        ans = (ans + solve(frst, lst)) % mod;
      Hell:;
      }
    } while (next_permutation(perm.begin(), perm.end()));
  }
  return cout << ans << endl, 0;
}
