import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main() {
  long n, m;
  readf("%d %d\n", &n, &m);

  auto xs = new long[](m);
  foreach (_; 0..n) {
    auto ys = readln.strip.split(" ").map!(to!int).array;
    foreach (y; ys[1..$]) {
      xs[y-1]++;
    }
  }

  writeln(xs.count(n));


}
