#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1ll;
  long long _tmp = mypow(_a, _x / 2, _mod);
  _tmp = (_tmp * _tmp) % _mod;
  if (_x & 1) _tmp = (_tmp * _a) % _mod;
  return _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x + _y;
  if (_ >= _mod) _ -= _mod;
  return _;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x - _y;
  if (_ < 0) _ += _mod;
  return _;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x * _y;
  if (_ >= _mod) _ %= _mod;
  return _;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
int n, a[2525][2525], b[2525][2525], p[2525], sz;
inline int find_p(int x) { return x == p[x] ? x : p[x] = find_p(p[x]); }
inline bool Union(int x, int y) {
  x = find_p(x);
  y = find_p(y);
  if (x == y) return false;
  p[x] = y;
  sz--;
  return true;
}
void build() {}
vector<pair<int, int> > v[2525];
vector<pair<int, pair<int, int> > > e;
void init() {
  sz = n = getint();
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      a[i][j] = getint();
      e.push_back(make_pair(a[i][j], make_pair(i, j)));
    }
  sort((e).begin(), (e).end());
  for (size_t i = 0; i < e.size() && sz > 1; i++)
    if (Union(e[i].second.first, e[i].second.second)) {
      v[e[i].second.first].push_back(make_pair(e[i].second.second, e[i].first));
      v[e[i].second.second].push_back(make_pair(e[i].second.first, e[i].first));
    }
}
bool got[2525];
queue<int> Q;
void BFS(int st) {
  for (int i = 1; i <= n; i++) got[i] = false;
  Q.push(st);
  got[st] = true;
  while (Q.size()) {
    int tn = Q.front();
    Q.pop();
    for (size_t i = 0; i < v[tn].size(); i++)
      if (!got[v[tn][i].first]) {
        got[v[tn][i].first] = true;
        b[st][v[tn][i].first] = max(b[st][tn], v[tn][i].second);
        Q.push(v[tn][i].first);
      }
  }
}
void solve() {
  for (int i = 1; i <= n; i++) BFS(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j] != b[i][j]) {
        puts("NOT MAGIC");
        return;
      }
  puts("MAGIC");
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
