#include <bits/stdc++.h>
using namespace std;
int dist[3002][3002] = {0};
vector<int> adj[3002];
void bfs(int u) {
  queue<pair<int, int> > Q;
  dist[u][u] = 0;
  int visited[3002] = {0};
  visited[u] = 1;
  Q.push(make_pair(u, 0));
  while (!Q.empty()) {
    pair<int, int> node = Q.front();
    Q.pop();
    for (int i = (0); i < (adj[node.first].size()); ++i) {
      int v = adj[node.first][i];
      if (!visited[v]) {
        dist[u][v] = dist[u][node.first] + 1;
        Q.push(make_pair(v, dist[u][v]));
        visited[v] = 1;
      }
    }
  }
}
int main() {
  int n, m, u, v, s, t, l, s1, t1, l1;
  scanf("%d", &n), scanf("%d", &m);
  for (int i = (0); i < (m); ++i) {
    scanf("%d", &u), scanf("%d", &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  scanf("%d", &s), scanf("%d", &t), scanf("%d", &l), scanf("%d", &s1),
      scanf("%d", &t1), scanf("%d", &l1);
  for (int i = (1); i < (n + 1); ++i) bfs(i);
  if (dist[s][t] > l || dist[s1][t1] > l1) {
    printf("-1\n");
    return 0;
  }
  int ans = dist[s][t] + dist[s1][t1];
  for (int i = (1); i < (n + 1); ++i)
    for (int j = (1); j < (n + 1); ++j) {
      int p1 = dist[s][i] + dist[i][j] + dist[j][t];
      int p2 = dist[s1][i] + dist[i][j] + dist[j][t1];
      p2 = min(p2, dist[s1][j] + dist[i][j] + dist[i][t1]);
      if (p1 <= l && p2 <= l1) ans = min(ans, p1 + p2 - dist[i][j]);
    }
  printf("%d\n", m - ans);
  return 0;
}
