#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int n, m, x, y;
vector<int> g[N];
int d[N][N];
int s1, t1, l1;
int s2, t2, l2;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) d[i][j] = -1;
  for (int i = 0; i < n; i++) {
    queue<int> q;
    d[i][i] = 0;
    q.push(i);
    while (!q.empty()) {
      int a = q.front();
      q.pop();
      for (int j = 0; j < g[a].size(); j++) {
        int b = g[a][j];
        if (d[i][b] == -1) {
          d[i][b] = d[i][a] + 1;
          q.push(b);
        }
      }
    }
  }
  cin >> s1 >> t1 >> l1;
  cin >> s2 >> t2 >> l2;
  s1--, t1--, s2--, t2--;
  int ans = m + 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int f1 = d[s1][i] + d[i][j] + d[j][t1];
      int f2 = d[s2][i] + d[i][j] + d[j][t2];
      int f3 = d[t1][i] + d[i][j] + d[j][s1];
      if (f1 <= l1 && f2 <= l2) ans = min(ans, f1 + f2 - d[i][j]);
      if (f3 <= l1 && f2 <= l2) ans = min(ans, f3 + f2 - d[i][j]);
    }
  }
  if (d[s1][t1] <= l1 && d[s2][t2] <= l2) ans = min(ans, d[s1][t1] + d[s2][t2]);
  cout << (m - ans);
  return 0;
}
