#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[5], b[5];
set<int> S;
bool ok = 1;
int lca(int x, int y) {
  if (x == y) return x;
  int u, v;
  for (int i = 0; i < 31; i++)
    if (((x >> i) & 1)) u = i;
  for (int i = 0; i < 31; i++)
    if (((y >> i) & 1)) v = i;
  if (u > v) {
    swap(u, v);
    swap(x, y);
  }
  while (u < v) {
    y /= 2;
    v--;
  }
  if (x == y) return x;
  int ans = 0;
  for (int i = u; i >= 0; i--) {
    if (((x >> i) & 1) + ((y >> i) & 1) == 1) {
      return ans;
    }
    ans = ans * 2 + ((x >> i) & 1);
  }
  return ans;
}
vector<int> path(int u, int v) {
  vector<int> A, B;
  int x = lca(u, v);
  while (u != x) {
    A.push_back(u);
    u /= 2;
  }
  A.push_back(x);
  while (v != x) {
    B.push_back(v);
    v /= 2;
  }
  reverse(B.begin(), B.end());
  for (int i = 0; i < B.size(); i++) A.push_back(B[i]);
  return A;
}
long long C(long long top) {
  if (top > n) return 0;
  long long L = top, R = top, ret = 0;
  while (1) {
    if (R >= n) {
      if (L <= n) ret += (n - L + 1);
      return ret;
    }
    ret += R - L + 1;
    L *= 2;
    R = R * 2 + 1;
  }
}
long long cnt(long long top, vector<pair<int, int> > vec) {
  if (top > n) return 0;
  if (S.find(top) != S.end()) return 0LL;
  vector<int> L;
  for (int i = 0; i < vec.size(); i++) {
    L.push_back(lca(vec[i].first, vec[i].second));
  }
  sort(L.begin(), L.end());
  L.erase(unique(L.begin(), L.end()), L.end());
  long long ret = C(top);
  for (int i = 0; i < L.size(); i++) {
    if (lca(top, L[i]) != top) continue;
    for (int j = 0; j < L.size(); j++) {
      if (i == j) continue;
      if (lca(top, L[j]) != top) continue;
      if (lca(L[i], L[j]) == L[j]) goto fail;
    }
    ret -= C(L[i]);
  fail:;
  }
  return ret;
}
void go(int u, int v) {
  vector<int> A, B;
  int x = lca(u, v);
  while (u != x) {
    A.push_back(u);
    u /= 2;
  }
  A.push_back(x);
  while (v != x) {
    B.push_back(v);
    v /= 2;
  }
  reverse(B.begin(), B.end());
  for (int i = 0; i < B.size(); i++) A.push_back(B[i]);
  for (int i = 0; i < A.size(); i++) {
    if (S.find(A[i]) != S.end()) {
      ok = 0;
    } else
      S.insert(A[i]);
  }
}
bool in(int u, int v) {
  vector<int> A, B;
  int x = lca(u, v);
  while (u != x) {
    A.push_back(u);
    u /= 2;
  }
  A.push_back(x);
  while (v != x) {
    B.push_back(v);
    v /= 2;
  }
  reverse(B.begin(), B.end());
  for (int i = 0; i < B.size(); i++) A.push_back(B[i]);
  for (int i = 0; i < A.size(); i++) {
    if (S.find(A[i]) != S.end()) return 0;
  }
  return 1;
}
long long calc(int top, vector<pair<int, int> > vec) {
  if (top > n) return 0;
  if (S.find(top) != S.end()) return 0LL;
  while (top != 1) {
    int top2 = top / 2;
    if (S.find(top2) != S.end()) return cnt(top, vec);
    top = top2;
  }
  return cnt(1, vec);
}
long long calc2(int u, int v, vector<pair<int, int> > vec) {
  if (S.find(u) != S.end()) return 0LL;
  if (S.find(v) != S.end()) return 0LL;
  if (u == v) return 0LL;
  vector<int> pat = path(u, v);
  int x = lca(u, v);
  vector<long long> cntt;
  for (int i = 0; i < pat.size(); i++) {
    assert(S.find(pat[i]) == S.end());
    if (pat[i] != x) {
      int y = 2 * pat[i], z = 2 * pat[i] + 1;
      int a = (i == 0 ? -1 : pat[i - 1]);
      int b = (i == pat.size() - 1 ? -1 : pat[i + 1]);
      long long C = 1;
      if (y == a || y == b)
        ;
      else
        C += cnt(y, vec);
      if (z == a || z == b)
        ;
      else
        C += cnt(z, vec);
      cntt.push_back(C);
    } else {
      int y = 2 * pat[i], z = 2 * pat[i] + 1;
      int a = (i == 0 ? -1 : pat[i - 1]);
      int b = (i == pat.size() - 1 ? -1 : pat[i + 1]);
      long long C = 1;
      if (y == a || y == b)
        ;
      else
        C += cnt(y, vec);
      if (z == a || z == b)
        ;
      else
        C += cnt(z, vec);
      int X = x;
      int pre = x;
      while (X != 1) {
        int XX = X / 2;
        if (S.find(XX) != S.end()) break;
        C++;
        y = 2 * XX, z = 2 * XX + 1;
        if (y == pre)
          ;
        else
          C += cnt(y, vec);
        if (z == pre)
          ;
        else
          C += cnt(z, vec);
        pre = XX;
        X = XX;
      }
      cntt.push_back(C);
    }
  }
  long long ret = 0, sum = 0;
  for (int i = 1; i < cntt.size(); i++) {
    sum += cntt[i - 1];
    sum %= 1000000007;
    ret += sum * cntt[i] % 1000000007;
  }
  return ret % 1000000007;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
  long long ret = 1LL * n * n;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < (1 << m); j++) {
      if (__builtin_popcount(j) != i) continue;
      vector<int> vi;
      for (int k = 0; k < m; k++)
        if (((j >> k) & 1)) vi.push_back(k);
      do {
        for (int k = 0; k < (1 << i); k++) {
          int x[5];
          for (int e = 0; e < i; e++) x[e] = (((k >> e) & 1));
          vector<pair<int, int> > vec;
          for (int y = 0; y < vi.size(); y++) {
            if (x[y]) {
              vec.push_back(make_pair(a[vi[y]], b[vi[y]]));
            } else {
              vec.push_back(make_pair(b[vi[y]], a[vi[y]]));
            }
          }
          S.clear();
          ok = 1;
          vector<pair<int, int> > vec2;
          for (int i = 1; i < vec.size(); i++) {
            go(vec[i - 1].second, vec[i].first);
            vec2.push_back(make_pair(vec[i - 1].second, vec[i].first));
          }
          if (ok == 0) continue;
          bool D = in(vec[0].first, vec[vec.size() - 1].second);
          if (vec[0].first == vec[vec.size() - 1].second) continue;
          if (D == 0) {
            ret += calc(vec[0].first, vec2) *
                   calc(vec[vec.size() - 1].second, vec2) % 1000000007;
            ret %= 1000000007;
          } else {
            ret += calc2(vec[0].first, vec[vec.size() - 1].second, vec2);
            ret %= 1000000007;
          }
        }
      } while (next_permutation(vi.begin(), vi.end()));
    }
  }
  cout << ret % 1000000007 << endl;
}
