#include <bits/stdc++.h>
using namespace std;
const int MX = 3004;
int n, m, s1, l1, t1, s2, l2, t2, dis[MX][MX], vis[MX], x, y;
vector<int> v[MX];
void BFS(int y) {
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) dis[y][i] = MX * MX;
  dis[y][y] = 0;
  queue<pair<int, int> > q;
  q.push({y, 0});
  while (!q.empty()) {
    int x = q.front().first, c = q.front().second;
    q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    dis[y][x] = c;
    for (auto pp : v[x]) {
      q.push({pp, c + 1});
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) BFS(i);
  cin >> s1 >> t1 >> l1;
  cin >> s2 >> t2 >> l2;
  if (dis[s1][t1] > l1 || dis[s2][t2] > l2) {
    puts("-1");
    return 0;
  }
  int ans = m - dis[s1][t1] - dis[s2][t2];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int dis1 = min(dis[s1][i] + dis[j][t1], dis[s1][j] + dis[i][t1]);
      int dis2 = min(dis[s2][i] + dis[j][t2], dis[s2][j] + dis[i][t2]);
      if (dis1 + dis[i][j] > l1) continue;
      if (dis2 + dis[i][j] > l2) continue;
      ans = max(ans, m - dis1 - dis2 - dis[i][j]);
    }
  }
  cout << ans << endl;
}
