#include <bits/stdc++.h>
using namespace std;
namespace SHENZHEBEI {
inline char gc() { return getchar(); }
inline long long read() {
  long long x = 0, f = 1;
  char ch = gc();
  for (; !isdigit(ch); ch = gc())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch;
  return x * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline char readchar() {
  char ch = gc();
  for (; isspace(ch); ch = gc())
    ;
  return ch;
}
inline long long readstr(char *s) {
  char ch = gc();
  int cur = 0;
  for (; isspace(ch); ch = gc())
    ;
  for (; !isspace(ch); ch = gc()) s[cur++] = ch;
  s[cur] = '\0';
  return cur;
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline double getreal() {
  static double lbc;
  scanf("%lf", &lbc);
  return lbc;
}
}  // namespace SHENZHEBEI
using namespace SHENZHEBEI;
const long long mod = 1e9 + 7, N = 200010;
map<long long, long long> g;
vector<long long> a[1010];
long long ans, n, m, vis[1010], SIZE[1010];
long long id(long long x) {
  if (g.find(x) == g.end()) {
    long long u = g.size();
    g[x] = u;
  }
  return g[x];
}
void gao(long long x) {
  for (; x; x >>= 1) id(x);
}
long long Size(long long x) {
  long long L = x, R = x, ans = 0;
  for (; L <= n; L = L << 1, R = R << 1 | 1)
    ans += ((n) < (R) ? (n) : (R)) - L + 1;
  return ans;
}
void dfs(long long x, long long bb) {
  vis[x] = 1;
  (ans = (ans + (bb * SIZE[x])) % mod);
  for (long long i : a[x])
    if (!vis[i]) dfs(i, bb);
  vis[x] = 0;
}
int main() {
  n = read(), m = read();
  for (long long i = 1; i <= m; ++i) {
    long long x = read(), y = read();
    gao(x), gao(y);
    a[g[x]].push_back(g[y]);
    a[g[y]].push_back(g[x]);
  }
  gao(1);
  for (pair<long long, long long> I : g) {
    SIZE[I.second] = Size(I.first);
    if (g.count(I.first * 2)) SIZE[I.second] -= Size(I.first * 2);
    if (g.count(I.first * 2 + 1)) SIZE[I.second] -= Size(I.first * 2 + 1);
    if (I.first > 1)
      a[g[I.first / 2]].push_back(g[I.first]),
          a[g[I.first]].push_back(g[I.first / 2]);
  }
  for (long long i = 0; i < g.size(); ++i) dfs(i, SIZE[i]);
  writeln(ans);
}
