#include <bits/stdc++.h>
using namespace std;
long long Set(long long N, long long pos) { return N = N | (1 << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
void CI(int &_x) { scanf("%d", &_x); }
void CO(long long &_x) { cout << _x; }
template <typename T>
void getarray(T a[], long long n) {
  for (long long i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void prLLIarray(T a[], long long n) {
  for (long long i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const long long INF = 0x7f7f7f7f;
long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
long long dr4[4] = {0, 0, 1, -1};
long long dc4[4] = {-1, 1, 0, 0};
long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
vector<int> G[3005];
int dis[3005];
void bfs(int src) {
  memset(dis, -1, sizeof dis);
  queue<int> Q;
  Q.push(src);
  dis[src] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (dis[v] != -1) continue;
      dis[v] = 1 + dis[u];
      Q.push(v);
    }
  }
}
int matrix[3005][3005];
int main() {
  int node, edge;
  cin >> node >> edge;
  for (long long i = 0; i < edge; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= node; i++) {
    bfs(i);
    for (int j = 1; j <= node; j++) matrix[i][j] = dis[j];
  }
  int s1, l1, t1;
  cin >> s1 >> t1 >> l1;
  int s2, l2, t2;
  cin >> s2 >> t2 >> l2;
  if (matrix[s1][t1] > l1 || matrix[s2][t2] > l2) {
    puts("-1");
    return 0;
  }
  int ans = matrix[s1][t1] + matrix[s2][t2];
  for (int i = 1; i <= node; i++)
    for (int j = 1; j <= node; j++) {
      int temp = matrix[s1][i] + matrix[i][j] + matrix[j][t1] + matrix[s2][i] +
                 matrix[j][t2];
      if (matrix[s1][i] + matrix[i][j] + matrix[j][t1] <= l1 &&
          matrix[s2][i] + matrix[i][j] + matrix[j][t2] <= l2)
        ans = min(ans, temp);
      temp = matrix[s1][i] + matrix[i][j] + matrix[j][t1] + matrix[t2][i] +
             matrix[j][s2];
      if (matrix[s1][i] + matrix[i][j] + matrix[j][t1] <= l1 &&
          matrix[t2][i] + matrix[i][j] + matrix[j][s2] <= l2)
        ans = min(ans, temp);
    }
  cout << edge - ans << "\n";
}
