#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long n, m;
int lca(int x, int y) {
  while (x != y) {
    if (x < y) swap(x, y);
    x /= 2;
  }
  return x;
}
pair<int, int> norm(pair<int, int> p) {
  if (p.first > p.second) swap(p.first, p.second);
  return p;
}
vector<pair<int, int> > get_path(pair<int, int> p) {
  int c = lca(p.first, p.second);
  if (c == p.first || c == p.second) return vector<pair<int, int> >(1, norm(p));
  vector<pair<int, int> > v(2, p);
  v[0].first = c;
  v[1].second = c;
  v[0] = norm(v[0]);
  v[1] = norm(v[1]);
  return v;
}
void add_path(vector<pair<int, int> >& v, pair<int, int> p) {
  vector<pair<int, int> > x = get_path(p);
  for (pair<int, int> t : x) v.push_back(t);
}
vector<int> up(int a, int b) {
  vector<int> v;
  while (a != b) {
    v.push_back(a);
    a /= 2;
  }
  return v;
}
const int DEBUG = 1;
bool intersect(pair<int, int> a, pair<int, int> b) {
  a = norm(a);
  b = norm(b);
  if (a.first < b.first) swap(a, b);
  bool res = false;
  if (lca(a.first, b.second) == a.first && lca(a.first, b.first) == b.first)
    res = true;
  if (0 && DEBUG) {
    assert(lca(a.second, a.first) == a.first);
    assert(lca(b.second, b.first) == b.first);
    vector<int> p1 = up(a.second, a.first);
    p1.push_back(a.first);
    sort(p1.begin(), p1.end());
    vector<int> p2 = up(b.second, b.first);
    p2.push_back(b.first);
    bool was = 0;
    for (int x : p2)
      if (binary_search(p1.begin(), p1.end(), x)) was = 1;
    assert(was == res);
  }
  return res;
}
bool intersect(const vector<pair<int, int> >& v, pair<int, int> a) {
  for (pair<int, int> x : v)
    if (intersect(x, a)) return true;
  return false;
}
bool intersect(const vector<pair<int, int> >& a,
               const vector<pair<int, int> >& b) {
  for (pair<int, int> x : a)
    for (pair<int, int> y : b)
      if (intersect(x, y)) return true;
  return false;
}
long long get_size(int v) {
  assert(v >= 1 && v <= n);
  long long l = v, r = v, res = 0;
  while (l <= n) {
    res += min(r, n) - l + 1;
    l *= 2;
    r = 2 * r + 1;
  }
  if (0 && DEBUG) {
    long long c = 0;
    for (int i = 1; i <= n; ++i)
      if (lca(i, v) == v) ++c;
    assert(c == res);
  }
  return res;
}
long long subtree(int v, const vector<pair<int, int> >& used) {
  assert(v);
  long long res = get_size(v);
  vector<int> u;
  for (pair<int, int> p : used) {
    if (lca(p.first, v) == v && p.first != v) {
      u.push_back(p.first);
    } else if (lca(v, p.second) == v && p.second != v) {
      int t = p.second;
      while (t / 2 != v) t /= 2;
      u.push_back(t);
    }
  }
  sort(u.begin(), u.end());
  u.resize(unique(u.begin(), u.end()) - u.begin());
  for (int i : u) {
    assert(lca(i, v) == v && i != v);
    bool ok = 1;
    for (int j : u)
      if (i != j && lca(i, j) == j) {
        ok = 0;
        break;
      }
    if (ok) res -= get_size(i);
  }
  assert(res >= 1);
  if (0 && DEBUG) {
    long long c = 1;
    for (int i = 1; i <= n; ++i) {
      if (lca(i, v) == v && i != v) {
        int t = i;
        while (t / 2 != v) t /= 2;
        if (!intersect(used, get_path(pair<int, int>(t, i)))) ++c;
      }
    }
    assert(c == res);
  }
  return res % mod;
}
int neig(int v, int i) {
  assert(v != i);
  if (lca(i, v) == v) {
    int t = i;
    while (t / 2 != v) t /= 2;
    return t;
  } else {
    assert(v != 1);
    return v / 2;
  }
}
long long calc(int v, vector<pair<int, int> > used) {
  assert(v);
  int v0 = v;
  long long res = 0;
  vector<pair<int, int> > used0 = used;
  while (1) {
    res += subtree(v, used);
    v /= 2;
    if (!v) break;
    if (intersect(used, pair<int, int>(v, v))) break;
    used.push_back(pair<int, int>(v, v));
  }
  if (0 && DEBUG) {
    long long c = 1;
    for (int i = 1; i <= n; ++i)
      if (i != v0) {
        if (lca(i, v0) == v0) {
          int t = i;
          while (t / 2 != v0) t /= 2;
          if (!intersect(used0, get_path(pair<int, int>(t, i)))) ++c;
        } else {
          assert(v0 != 1);
          int t = v0 / 2;
          if (!intersect(used0, get_path(pair<int, int>(t, i)))) ++c;
        }
      }
    assert(c == res);
  }
  return res % mod;
}
long long solve(int b, int e, const vector<pair<int, int> >& used) {
  assert(b != e);
  int c = lca(b, e);
  vector<int> p1 = up(b, c), p2 = up(e, c);
  vector<int> p = p1;
  p.push_back(c);
  reverse(p2.begin(), p2.end());
  for (auto x : p2) p.push_back(x);
  assert(p.size() >= 2 && p[0] == b && p.back() == e);
  long long res = 0;
  for (int i = 1; i < (int)p.size(); ++i) {
    vector<pair<int, int> > add = (i != 1)
                                      ? get_path(pair<int, int>(p[1], p[i - 1]))
                                      : vector<pair<int, int> >(0);
    if (intersect(used, add)) break;
    for (int j = i - 1; j + 1 < (int)p.size(); ++j) {
      vector<pair<int, int> > add1 =
          (j + 3 <= (int)p.size())
              ? get_path(pair<int, int>(p[j + 1], p[p.size() - 2]))
              : vector<pair<int, int> >(0);
      if (intersect(used, add1)) continue;
      assert(!intersect(add, add1));
      vector<pair<int, int> > u = used;
      add_path(u, pair<int, int>(b, e));
      res = (res + calc(p[i - 1], u) * calc(p[j + 1], u)) % mod;
    }
  }
  if (0 && DEBUG) {
    long long s = 0;
    for (int i = 1; i <= n; ++i) {
      vector<pair<int, int> > u = used;
      if (i != b) {
        int t = neig(b, i);
        if (intersect(used, get_path(pair<int, int>(t, i)))) continue;
        add_path(u, pair<int, int>(t, i));
      }
      for (int j = 1; j <= n; ++j) {
        if (j != e) {
          int t = neig(e, j);
          if (intersect(u, get_path(pair<int, int>(t, j)))) continue;
        }
        ++s;
      }
    }
    assert(s % mod == res);
  }
  return res % mod;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  long long res = n * n % mod;
  for (int mask = 1; mask < (1 << m); ++mask) {
    vector<pair<int, int> > x;
    for (int i = 0; i < m; ++i)
      if (mask & (1 << i)) {
        x.push_back(v[i]);
      }
    for (int m1 = 0; m1 < (1 << x.size()); ++m1) {
      vector<pair<int, int> > y = x;
      for (int i = 0; i < (int)x.size(); ++i)
        if (m1 & (1 << i)) swap(y[i].first, y[i].second);
      vector<int> ord(x.size());
      for (int i = 0; i < (int)ord.size(); ++i) ord[i] = i;
      do {
        vector<pair<int, int> > z = y;
        for (int i = 0; i < (int)ord.size(); ++i) z[i] = y[ord[i]];
        vector<pair<int, int> > used(1);
        used[0] = pair<int, int>(z[0].first, z[0].first);
        bool ok = z[0].first != z[0].second;
        pair<int, int> ep(z[0].second, z[0].second);
        for (int i = 1; i < (int)ord.size(); ++i) {
          if (z[i].first != z[i - 1].second) {
            vector<pair<int, int> > t =
                get_path(pair<int, int>(z[i - 1].second, z[i].first));
            if (intersect(used, t)) {
              ok = 0;
              break;
            }
            for (pair<int, int> x1 : t) used.push_back(x1);
          } else {
            used.push_back(ep);
          }
          ep = pair<int, int>(z[i].second, z[i].second);
          if (intersect(used, ep)) {
            ok = 0;
            break;
          }
        }
        used.push_back(ep);
        if (ok) {
          res = (res + solve(z[0].first, z.back().second, used)) % mod;
        }
      } while (next_permutation(ord.begin(), ord.end()));
    }
  }
  cout << (res % mod + mod) % mod << endl;
  return 0;
}
