#include <bits/stdc++.h>
using namespace std;
void FastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
vector<vector<int> > shortestPath;
vector<vector<int> > V;
void bfs(int pos) {
  queue<int> q;
  q.push(pos);
  shortestPath[pos][pos] = 0;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (int i = 0; i < V[p].size(); i++) {
      int t = V[p][i];
      if (shortestPath[pos][t] == INT_MAX) {
        q.push(t);
      }
      shortestPath[pos][t] =
          min(shortestPath[pos][t], shortestPath[pos][p] + 1);
    }
  }
}
int main() {
  FastIO();
  int n, m, s1, t1, l1, s2, t2, l2, a, b;
  cin >> n >> m;
  shortestPath.assign(n + 1, vector<int>(n + 1, INT_MAX));
  V.assign(n + 1, vector<int>());
  for (int i = 0; i < (int)m; i++) {
    cin >> a >> b;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  cin >> s1 >> t1 >> l1 >> s2 >> t2 >> l2;
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  if (shortestPath[s1][t1] > l1 || shortestPath[s2][t2] > l2) {
    cout << "-1" << '\n';
    return 0;
  }
  int ans = m - (shortestPath[s1][t1] + shortestPath[s2][t2]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (shortestPath[s1][i] + shortestPath[i][j] + shortestPath[j][t1] <=
              l1 &&
          shortestPath[s2][i] + shortestPath[i][j] + shortestPath[j][t2] <=
              l2) {
        ans = max(ans, m - shortestPath[s1][i] - shortestPath[i][j] -
                           shortestPath[j][t1] - shortestPath[s2][i] -
                           shortestPath[j][t2]);
      }
      swap(s1, t1);
      if (shortestPath[s1][i] + shortestPath[i][j] + shortestPath[j][t1] <=
              l1 &&
          shortestPath[s2][i] + shortestPath[i][j] + shortestPath[j][t2] <=
              l2) {
        ans = max(ans, m - shortestPath[s1][i] - shortestPath[i][j] -
                           shortestPath[j][t1] - shortestPath[s2][i] -
                           shortestPath[j][t2]);
      }
      swap(s1, t1);
    }
  }
  cout << ans << '\n';
  return 0;
}
