#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a[3003];
int d[3003][3003];
void bfs(int u, int id) {
  for (int i = 1; i <= n; i++) {
    d[id][i] = 1e9;
  }
  d[id][u] = 0;
  queue<int> Q;
  Q.push(u);
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    for (int v : a[u]) {
      if (d[id][v] > d[id][u] + 1) {
        d[id][v] = d[id][u] + 1;
        Q.push(v);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    bfs(i, i);
  }
  int s1, s2, t1, t2, l1, l2;
  cin >> s1 >> t1 >> l1 >> s2 >> t2 >> l2;
  if (d[s1][t1] > l1 || d[s2][t2] > l2) {
    return cout << -1, 0;
  }
  int res = d[s1][t1] + d[s2][t2];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (d[s1][i] + d[i][j] + d[j][t1] <= l1) {
        if (d[s2][i] + d[i][j] + d[j][t2] <= l2) {
          int S = d[s1][i] + d[s2][i] + d[i][j] + d[j][t1] + d[j][t2];
          res = min(res, S);
        }
        if (d[t2][i] + d[i][j] + d[j][s2] <= l2) {
          int S = d[s1][i] + d[t2][i] + d[i][j] + d[j][t1] + d[j][s2];
          res = min(res, S);
        }
      }
    }
  }
  cout << m - res;
  return 0;
}
