#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int d[N][N];
vector<int> g[N];
int main() {
  ios_base::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(d, -1, sizeof d);
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    queue<int> q;
    q.push(i);
    d[i][i] = 0;
    while (!q.empty()) {
      int s = q.front();
      q.pop();
      for (int j = 0; j < int(g[s].size()); j++) {
        int to = g[s][j];
        if (d[i][to] == -1) {
          d[i][to] = d[i][s] + 1;
          q.push(to);
        }
      }
    }
  }
  int s[2], t[2], l[2];
  scanf("%d %d %d", &s[0], &t[0], &l[0]);
  scanf("%d %d %d", &s[1], &t[1], &l[1]);
  s[0]--, t[0]--, s[1]--, t[1]--;
  int ans = m + 1;
  for (int k = 0; k < 2; k++) {
    swap(s[0], t[0]);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int v[] = {d[s[0]][i] + d[i][j] + d[j][t[0]],
                   d[s[1]][i] + d[i][j] + d[j][t[1]]};
        if (v[0] <= l[0] && v[1] <= l[1]) {
          ans = min(ans, v[0] + v[1] - d[i][j]);
        }
      }
    }
  }
  if (d[s[0]][t[0]] <= l[0] && d[s[1]][t[1]] <= l[1]) {
    ans = min(ans, d[s[0]][t[0]] + d[s[1]][t[1]]);
  }
  if (ans > m) {
    ans = -1;
  } else {
    ans = m - ans;
  }
  cout << ans;
}
