#include <bits/stdc++.h>
using namespace std;
int s, n, k, a, b, c, x, y, z, p = 10000, i, j, m[3005][3005];
vector<int> v[3005];
queue<pair<int, int> > q;
unordered_map<int, int> mp;
int main() {
  cin >> n >> k;
  while (i < k) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    i++;
  }
  i = 1;
  j = 0;
  while (i <= n) {
    q.push({i, 0});
    mp[i]++;
    while (!q.empty()) {
      while (j < v[q.front().first].size()) {
        if (mp[v[q.front().first][j]] == 0)
          q.push({v[q.front().first][j], q.front().second + 1}),
              m[i][v[q.front().first][j]] = q.front().second + 1,
              mp[v[q.front().first][j]]++;
        j++;
      }
      j = 0;
      q.pop();
    }
    i++;
    mp.clear();
  }
  i = 1;
  j = 1;
  cin >> a >> b >> c >> x >> y >> z;
  while (i <= n) {
    while (j <= n) {
      if (m[a][i] + m[i][j] + m[j][b] <= c && m[x][i] + m[i][j] + m[j][y] <= z)
        p = min(p, m[a][i] + m[i][j] + m[j][b] + m[x][i] + m[j][y]);
      if (m[a][i] + m[i][j] + m[j][b] <= c && m[x][j] + m[i][j] + m[i][y] <= z)
        p = min(p, m[a][i] + m[i][j] + m[j][b] + m[x][j] + m[i][y]);
      j++;
    }
    i++;
    j = 1;
  }
  if (m[a][b] <= c && m[x][y] <= z) p = min(p, m[a][b] + m[x][y]);
  if (p == 10000)
    cout << -1;
  else
    cout << k - p;
}
