#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 100;
vector<int> adj[maxn];
queue<int> q;
int d[maxn][maxn];
bool mark[maxn];
void bfs(int sr) {
  d[sr][sr] = 0;
  q.push(sr);
  mark[sr] = true;
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < adj[v].size(); i++) {
      int u = adj[v][i];
      if (!mark[u]) {
        q.push(u);
        mark[u] = true;
        d[sr][u] = d[sr][v] + 1;
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  int s1, t1, l1;
  int s2, t2, l2;
  cin >> s1 >> t1 >> l1;
  cin >> s2 >> t2 >> l2;
  for (int i = 1; i <= n; i++) {
    bfs(i);
    memset(mark, false, sizeof mark);
  }
  int ans = 1e4;
  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 and
          d[s2][i] + d[i][j] + d[j][t2] <= l2)
        ans = min(ans, d[s1][i] + d[s2][i] + d[i][j] + d[j][t1] + d[j][t2]);
  swap(s1, t1);
  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 and
          d[s2][i] + d[i][j] + d[j][t2] <= l2)
        ans = min(ans, d[s1][i] + d[s2][i] + d[i][j] + d[j][t1] + d[j][t2]);
  if (d[s1][t1] <= l1 and d[s2][t2] <= l2)
    ans = min(ans, d[s1][t1] + d[s2][t2]);
  cout << (ans == 1e4 ? -1 : m - ans) << endl;
  return 0;
}
