#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int M = 100;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
const int P = 1336;
const long double eps = 0.000000001;
const int inf = 1e9;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, uk;
vector<int> g[N];
unordered_map<int, int> mp;
map<pair<int, int>, int> st;
int zn[N], a[N], u[N];
int d = 0, s;
int get(int v) {
  if (v > n) return 0;
  int cl = v * 2, cr = v * 2 + 1, ans = 1;
  while (cl <= n) {
    ans += min(cr, n) - cl + 1;
    cl *= 2;
    cr = cr * 2 + 1;
  }
  return ans;
}
void add(int v) {
  if (mp.count(v)) return;
  uk++;
  mp[v] = uk;
  zn[uk] = v;
  int pred = uk;
  v /= 2;
  while (v) {
    bool f = mp.count(v);
    if (!f) {
      uk++;
      mp[v] = uk;
      zn[uk] = v;
    }
    int z = mp[v];
    g[z].push_back(pred);
    g[pred].push_back(z);
    if (f) return;
    pred = z;
    v /= 2;
  }
}
void calc() {
  for (int i = 1; i <= uk; i++) {
    int z = zn[i];
    bool f1 = 0, f2 = 0;
    for (auto to : g[i]) {
      if (zn[to] == z * 2) f1 = 1;
      if (zn[to] == z * 2 + 1) f2 = 1;
    }
    if (!f1) a[i] += get(z * 2);
    if (!f2) a[i] += get(z * 2 + 1);
  }
}
void DFS(int v, int k) {
  u[v] = 1;
  if (k == 0) d = (1ll * d + (1ll * (a[s] + 1) * (a[v] + 1)) % mod) % mod;
  for (auto to : g[v]) {
    if (u[to]) continue;
    int fl = st[{zn[v], zn[to]}];
    DFS(to, k - fl);
  }
  u[v] = 0;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int m;
  cin >> n >> m;
  vector<pair<int, int> > e;
  e.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> e[i].first >> e[i].second;
  }
  int ans = (1ll * n * n) % mod;
  for (int mask = 1; mask < (1 << m); mask++) {
    for (int i = 0; i < N; i++) {
      g[i].clear();
      u[i] = 0;
      a[i] = 0;
    }
    st.clear();
    mp.clear();
    uk = 0;
    int kol = 0;
    for (int i = 0; i < m; i++) {
      bool bit = (mask & (1 << i));
      if (bit) {
        add(e[i].first);
        add(e[i].second);
        st[{e[i].first, e[i].second}] = 1;
        st[{e[i].second, e[i].first}] = 1;
        kol++;
      }
    }
    calc();
    for (int i = 0; i < m; i++) {
      bool bit = (mask & (1 << i));
      if (bit) {
        int v = mp[e[i].first], vv = mp[e[i].second];
        bool f = 1;
        for (auto to : g[v]) {
          if (to == vv) {
            f = 0;
            break;
          }
        }
        if (f) {
          g[v].push_back(vv);
          g[vv].push_back(v);
        }
      }
    }
    for (int i = 1; i <= uk; i++) {
      d = 0;
      s = i;
      for (int j = 0; j <= uk; j++) {
        u[j] = 0;
      }
      DFS(i, kol);
      ans = (1ll * ans + d) % mod;
    }
  }
  cout << ans;
}
