#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int SIZE = 1e6 + 10;
struct data {
  int v;
  int id;
  data(int _v, int _id) : v(_v), id(_id) {}
  bool operator<(const data& b) const { return v > b.v; }
};
struct Dijkstra {
  vector<pair<int, int> > e[SIZE];
  int mi[SIZE];
  bool used[SIZE];
  int n, tt;
  void init(int _n) {
    n = _n;
    for (int i = 0; i < (n + 1); ++i) e[i].clear();
  }
  void add_edge(int x, int y, int v = 1) {
    e[x].push_back(make_pair(y, v));
    e[y].push_back(make_pair(x, v));
  }
  int dis(int st) {
    priority_queue<data> qq;
    for (int i = 0; i < (n + 1); ++i) mi[i] = INF, used[i] = 0;
    mi[st] = 0;
    qq.push(data(0, st));
    while (!qq.empty()) {
      data now = qq.top();
      qq.pop();
      if (used[now.id]) continue;
      used[now.id] = 1;
      for (int i = 0; i < (((int)(e[now.id]).size())); ++i) {
        int y = e[now.id][i].first;
        if (mi[y] > now.v + e[now.id][i].second) {
          mi[y] = now.v + e[now.id][i].second;
          qq.push(data(mi[y], y));
        }
      }
    }
    return -1;
  }
} dij;
int dd[3001][3001];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  dij.init(n);
  for (int i = 0; i < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    dij.add_edge(x, y);
  }
  int st1, ed1, L1;
  scanf("%d%d%d", &st1, &ed1, &L1);
  st1--;
  ed1--;
  int st2, ed2, L2;
  scanf("%d%d%d", &st2, &ed2, &L2);
  st2--;
  ed2--;
  for (int i = 0; i < (n); ++i) {
    dij.dis(i);
    for (int j = 0; j < (n); ++j) dd[i][j] = dij.mi[j];
  }
  if (dd[st1][ed1] > L1 || dd[st2][ed2] > L2)
    puts("-1");
  else {
    int res = dd[st1][ed1] + dd[st2][ed2];
    for (int i = 0; i < (n); ++i)
      for (int j = 0; j < (n); ++j) {
        int now = dd[i][j];
        if (now >= INF) continue;
        int v1 = min(dd[st1][i] + dd[j][ed1], dd[st1][j] + dd[i][ed1]);
        if (v1 + now > L1) continue;
        int v2 = min(dd[st2][i] + dd[j][ed2], dd[st2][j] + dd[i][ed2]);
        if (v2 + now > L2) continue;
        res = min(res, now + v1 + v2);
      }
    printf("%d\n", m - res);
  }
  return 0;
}
