#include <algorithm>
#include <utility>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define lsb(x) (x&-x)
#define msb(x) (1 << (31-clz(x)))
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define popcount(x) __builtin_popcount(x)
#define scan_type(t,fmt) int scan(t &x){return scanf(fmt, &x);}
#define print_type(t,fmt) int print(t const&x){return printf(fmt, x);}
#define println_type(t,fmt) int println(t const&x){return printf(fmt"\n", x);}
#define def_type(t, fmt) scan_type(t,fmt) print_type(t,fmt) println_type(t,fmt)
def_type(int, "%d");
def_type(ll, "%lld");
def_type(ull, "%llu");
def_type(float, "%f");
def_type(double, "%lf");
def_type(char, "%c");
// def_type(char *, "%s");
#include <bits/stdc++.h>
int const N = 1e5;
int n, m;
struct node {
int key, id;
node *l, *r = l = nullptr;
node(int k, int i) {
key = k;
id = i;
}
~node() {
if (l)
delete l;
if (r)
delete r;
}
};
node *root = nullptr;
char h[int (10e6) + 16];
void insert(int x, int id) {
if (root == nullptr) {
root = new node(x, id);
return;
}
auto p = root;
int i = 0;
bool okay = false;
while (!okay)
if (p->id != id)
p->id = id, p->key = x, okay = true;
else if (h[i] ^= 1, i = i * 2 + 1, x < p->key)
if (p->l)
p = p->l;
else
p->l = new node(x, id), okay = true;
else if (h[i] ^= 2, i = i * 2 + 2, x >= p->key)
if (p->r)
p = p->r;
else
p->r = new node(x, id), okay = true;
}
int main() {
scan(n), scan(m);
fill(h, h + int (10e6), '0');
map < string, bool > mm;
while (n--) {
for (int i = 0; i < m; ++i) {
int x;
scan(x);
insert(x, n);
}
mm[h] = true;
fill(h, h + int (10e6), '0');
}
println(int (mm.size()));
}
CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw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ID0gazsKICAgIGlkID0gaTsKICB9CiAgCiAgfm5vZGUoKSB7CiAgICBpZiAobCkKICAgICAgZGVsZXRlIGw7CiAgICBpZiAocikKICAgICAgZGVsZXRlIHI7CiAgfQp9OwoKbm9kZSAqcm9vdCA9IG51bGxwdHI7CmNoYXIgaFtpbnQgKDEwZTYpICsgMTZdOwoKdm9pZCBpbnNlcnQoaW50IHgsIGludCBpZCkgewogIGlmIChyb290ID09IG51bGxwdHIpIHsKICAgIHJvb3QgPSBuZXcgbm9kZSh4LCBpZCk7CiAgICByZXR1cm47CiAgfQoKICBhdXRvIHAgPSByb290OwogIGludCBpID0gMDsKICBib29sIG9rYXkgPSBmYWxzZTsKICB3aGlsZSAoIW9rYXkpCiAgICBpZiAocC0+aWQgIT0gaWQpCiAgICAgIHAtPmlkID0gaWQsIHAtPmtleSA9IHgsIG9rYXkgPSB0cnVlOwogICAgZWxzZSBpZiAoaFtpXSBePSAxLCBpID0gaSAqIDIgKyAxLCB4IDwgcC0+a2V5KQogICAgICBpZiAocC0+bCkKICAgICAgICBwID0gcC0+bDsKICAgICAgZWxzZQogICAgICAJcC0+bCA9IG5ldyBub2RlKHgsIGlkKSwgb2theSA9IHRydWU7CiAgICBlbHNlIGlmIChoW2ldIF49IDIsIGkgPSBpICogMiArIDIsIHggPj0gcC0+a2V5KQogICAgICBpZiAocC0+cikKICAgICAgCXAgPSBwLT5yOwogICAgICBlbHNlCgkgICAgICBwLT5yID0gbmV3IG5vZGUoeCwgaWQpLCBva2F5ID0gdHJ1ZTsKfQoKaW50IG1haW4oKSB7CiAgc2NhbihuKSwgc2NhbihtKTsKICBmaWxsKGgsIGggKyBpbnQgKDEwZTYpLCAnMCcpOwogIG1hcCA8IHN0cmluZywgYm9vbCA+IG1tOwogIHdoaWxlIChuLS0pIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgKytpKSB7CiAgICAgIGludCB4OwogICAgICBzY2FuKHgpOwogICAgICBpbnNlcnQoeCwgbik7CiAgICB9CiAgICBtbVtoXSA9IHRydWU7CiAgICBmaWxsKGgsIGggKyBpbnQgKDEwZTYpLCAnMCcpOwogIH0KCiAgcHJpbnRsbihpbnQgKG1tLnNpemUoKSkpOwp9