#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
const int N = 200010;
const int inf = 1e9;

vector<pii> G[N];

int main()
{
    /**
     * Input format:
     * first line: n m
     * each hyperedge line: num_nodes weight node1 node2 node3 ... nodelast
     * last line: s t
     */
    int n, m;
    scanf("%d%d", &n, &m);
    // construct edges in hypergraph
    for (int i = 0; i < m; ++i) {
        int c, w;
        scanf("%d%d", &c, &w);
        while (c--) {
            int v;
            scanf("%d", &v);
            G[v].push_back({n+i, w});
            G[n+i].push_back({v, 0});
        }
    }
    int s, t;
    scanf("%d%d", &s, &t);

    // normal dijkstra
    vector<int> dist(n+m, inf);
    vector<bool> visited(n+m, false);
    dist[s] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> Q;
    Q.push({dist[s], s});
    while (!Q.empty()) {
        int u = Q.top().second;
        Q.pop();
        if (visited[u])
            continue;
        visited[u] = true;
        if (u == t)
            break;
        for (auto vw : G[u]) {
            int v = vw.first, w = vw.second;
            if (!visited[v] && dist[u]+w < dist[v]) {
                dist[v] = dist[u]+w;
                Q.push({dist[v], v});
            }
        }
    }
    printf("%d\n", visited[t] ? dist[t] : -1);
    
    return 0;
}