#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
vector<int> g[N];
bool was[N];
int dist[N][N], q[N], s1, t1, l1, s2, l2, t2;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    memset(was, false, sizeof(was));
    int l, r;
    l = r = 0;
    q[r++] = i;
    was[i] = 1;
    while (l < r) {
      int now = q[l++];
      for (int to : g[now]) {
        if (!was[to]) {
          dist[i][to] = dist[i][now] + 1;
          was[to] = 1;
          q[r++] = to;
        }
      }
    }
  }
  cin >> s1 >> t1 >> l1 >> s2 >> t2 >> l2;
  int res = -1;
  if (dist[s1][t1] <= l1 && dist[s2][t2] <= l2) {
    res = m - (dist[s1][t1] + dist[s2][t2]);
  }
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= n; b++) {
      if (dist[s1][a] + dist[b][t1] + dist[a][b] <= l1 &&
          dist[s2][a] + dist[b][t2] + dist[a][b] <= l2) {
        res = max(res, m - (dist[s1][a] + dist[s2][a] + dist[a][b] +
                            dist[b][t1] + dist[b][t2]));
      }
      if (dist[s1][a] + dist[b][t1] + dist[a][b] <= l1 &&
          dist[s2][b] + dist[a][t2] + dist[a][b] <= l2) {
        res = max(res, m - (dist[s1][a] + dist[s2][b] + dist[a][b] +
                            dist[b][t1] + dist[a][t2]));
      }
    }
  }
  cout << res << endl;
  return 0;
}
