#!/usr/bin/perl -w

use strict;
use Data::Dumper;

local $/ = "\n\n";

my $sum = 0;

while (<>) {
	my $nper = 0;
	my %q;
	for my $per (split /\n/) {
		$nper++;
		$q{$_}++ for grep { /\S/ } split(//, $per);
	}
	my $count = grep { $q{$_} == $nper } keys %q;
	$sum += $count;
}

print "$sum\n";

