3
rjnflsbpxqivrcdjptj
vpojopbwbwbswdu
rydkiwnugwddcgcrng
 1
z
 30
b
u
p
n
f
m
t
i
j
k
p
h
a
c
w
z
z
p
t
d
o
w
u
q
l
y
i
o
a
u
 5
splt
ohqykk
xqpz
knojbur
pmfm
 2
hk
obsp
 5
zzxpfk
abcdefghijklmnopqrst
uvwxz
srgkjaskldfkln
vgnsdfdgfh
 2
rxscdzkkezud
wjehahqgouqvjienq
 5
ojdfhi
abcdefghijklmnopqrst
uvwxyz
ddfhdfhlasjt
qqq
 1
epkotfpkkrhhmuipmtdk
 10
kpmwcdoysw
gtpr
kuzoxmiixxbl
crgqtuo
jhbplhpklrgwnaugdf
zuxdaat
aycv
qwghrkqwkobrgevsjrk
tdxgc
lxyzgcmbzulcst
 5
dfijdfhi
abcdefghijklmnopqrst
uvwxy
kopsdfgiopjipw
jty
 2
xlaxwpjabtpwddc
txwdjmohrrszorrnomc
 1
a
 30
waiphwcqrrinr
o
qiqehzmgsjdoqd
kjexeesevrlowxhghq
judikhzkj
z
xo
lsdzypkfqro
sshgcxsky
gecntpcmoojfwp
svmytmcfhc
jrsrvsvbaiumlmkptn
s
wpcsovfjlyspviflk
ktvyzvddgllht
szahigtmklglrcocbo
znligfxkgxzkcfeu
liryvzmqwhr
xgrxkgiehxztv
etrjxdczppafly
jrdgajschhwsci
doxnxbjwptnimjmsuijx
zciwkbvrhgsjhrr
ehh
bzlnmd
xpbtbpftimnn
khbknqbvdkdd
mldj
skrvnyz
avptgpjmenfzfxwckmt
 30
e
x
itaubd
xcn
v
x
i
ci
aqs
zbi
q
cvdu
a
jos
qy
fjf
nayke
ge
s
q
qwad
gvz
o
ubn
nzoc
h
wnjwjrf
t
bq
bw
 1
b

a
 a
 e
 a
 a
 y
 b
 aa
 a
 ab
 z
 e
 b
 aa
 l
 a

#include <bits/stdc++.h>
using namespace std;
int n, m, l[101][101], x, y, res = 0, xet[101];
vector<int> a[101], e[101];
void DFS(int u) {
  xet[u] = 1;
  for (typeof(a[u].begin()) v = a[u].begin(); v != a[u].end(); v++) {
    if (xet[*v] == 0) DFS(*v);
  }
}
void thuchien() {
  memset(xet, 0, sizeof(xet));
  for (int i = 1; i <= n; i++)
    if (xet[i] == 0) {
      DFS(i);
      res++;
    }
  cout << res - 1 << endl;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    for (int j = 1; j <= x; j++) {
      cin >> y;
      e[y].push_back(i);
    }
  }
  for (int i = 1; i <= 100; i++)
    for (typeof(e[i].begin()) j = e[i].begin(); j != e[i].end(); j++)
      for (typeof(e[i].begin()) k = e[i].begin(); k != e[i].end(); k++)
        if (*j != *k) {
          a[*j].push_back(*k);
          a[*k].push_back(*j);
        }
  thuchien();
  return 0;
}
