#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[3005];
int s1, t1, l1, s2, t2, l2, dp[3005][3005], dist1, dist2;
bool vis[3005];
void bfs(int v) {
  memset(vis, 0, sizeof(vis));
  queue<int> q;
  q.push(v);
  dp[v][v] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 1;
    for (auto i : g[u]) {
      if (!vis[i]) {
        vis[i] = 1;
        dp[v][i] = dp[v][u] + 1;
        q.push(i);
      }
    }
  }
}
int main() {
  cin >> n >> m;
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cin >> s1 >> t1 >> l1;
  cin >> s2 >> t2 >> l2;
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  dist1 = min(dp[s1][t1], dp[t1][s1]);
  dist2 = min(dp[s2][t2], dp[t2][s2]);
  if (dist1 > l1 or dist2 > l2) {
    cout << -1;
    exit(0);
  }
  int mx = m - dp[s1][t1] - dp[s2][t2];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dist1 = dp[s1][i] + dp[i][j] + dp[j][t1];
      dist2 = dp[s2][i] + dp[i][j] + dp[j][t2];
      if (dist1 <= l1 and dist2 <= l2)
        mx = max(mx, m - dist1 - dist2 + dp[i][j]);
      dist1 = dp[t1][i] + dp[i][j] + dp[j][s1];
      if (dist1 <= l1 and dist2 <= l2)
        mx = max(mx, m - dist1 - dist2 + dp[i][j]);
    }
  }
  cout << mx << '\n';
}
