#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, s, t, l, o, p, q, a;
vector<int> v[3030];
int k[3030][3030];
bool d[3001];
void b(int i) {
  int u;
  queue<int> q;
  q.push(i);
  memset(d, 0, sizeof(d));
  d[i] = true;
  while (!q.empty()) {
    u = q.front(), q.pop();
    for (int g : v[u]) {
      if (!d[g]) {
        q.push(g);
        d[g] = true;
        k[i][g] = k[i][u] + 1;
      }
    }
  }
}
int bf(int i, int j) {
  int g, e, w = k[i][j];
  g = k[s][i] + k[j][t] + w;
  e = k[o][i] + k[j][p] + w;
  if (g > l || e > q) return m + 1;
  w = g + e - w;
  return w;
}
int bfs() {
  int g = m + 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) g = min(g, bf(i, j));
  if (k[s][t] <= l && k[o][p] <= q) g = min(g, k[s][t] + k[o][p]);
  return m - g;
}
int main() {
  cin >> n >> m;
  int g = -1;
  while (++g < m) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) b(i);
  cin >> s >> t >> l >> o >> p >> q;
  a = bfs();
  swap(s, t);
  a = max(a, bfs());
  cout << a;
}
