Vanya is in the palace that can be represented as a grid n × m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x ≤ p - 1 contains a key that can open any chest of type x + 1, and all chests of type 1 are not locked. There is exactly one chest of type p and it contains a treasure.

Vanya starts in cell (1, 1) (top left corner). What is the minimum total distance Vanya has to walk in order to get the treasure? Consider the distance between cell (r1, c1) (the cell in the row r1 and column c1) and (r2, c2) is equal to |r1 - r2| + |c1 - c2|.

Input

The first line of the input contains three integers n, m and p (1 ≤ n, m ≤ 300, 1 ≤ p ≤ n·m) — the number of rows and columns in the table representing the palace and the number of different types of the chests, respectively.

Each of the following n lines contains m integers aij (1 ≤ aij ≤ p) — the types of the chests in corresponding rooms. It's guaranteed that for each x from 1 to p there is at least one chest of this type (that is, there exists a pair of r and c, such that arc = x). Also, it's guaranteed that there is exactly one chest of type p.

Output

Print one integer — the minimum possible total distance Vanya has to walk in order to get the treasure from the chest of type p.

Examples

Input

3 4 3
2 1 1 1
1 1 1 1
2 1 1 3


Output

5


Input

3 3 9
1 3 5
8 9 7
4 6 2


Output

22


Input

3 4 12
1 2 3 4
8 7 6 5
9 10 11 12


Output

11
#include <bits/stdc++.h>
using namespace std;
int break_point() {
  char c;
  while ((c = getchar()) != '\n')
    ;
  return 0;
}
template <typename T>
void read_integer(T &r) {
  bool sign = 0;
  r = 0;
  char c;
  while (1) {
    c = getchar();
    if (c == '-') {
      sign = 1;
      break;
    }
    if (c != ' ' && c != '\n') {
      r = c - '0';
      break;
    }
  }
  while (1) {
    c = getchar();
    if (c == ' ' || c == '\n') break;
    r = r * 10 + (c - '0');
  }
  if (sign) r = -r;
}
long long binpowmod(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= mod;
      b--;
    } else {
      a *= a;
      a %= mod;
      b >>= 1;
    }
  }
  return res;
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      b--;
    } else {
      a *= a;
      b >>= 1;
    }
  }
  return res;
}
inline int getbit(int x, int b) { return (x >> b) & 1; }
inline long long getbit(long long x, int b) { return (x >> b) & 1; }
inline unsigned long long getbit(unsigned long long x, int b) {
  return (x >> b) & 1;
}
inline int setbit(int x, int b) { return x | (1 << b); }
inline void _setbit(int &x, int b) { x = setbit(x, b); }
inline long long setbit(long long x, int b) { return x | (1ll << b); }
inline void _setbit(long long &x, int b) { x = setbit(x, b); }
inline int unsetbit(int x, int b) { return x & (INT_MAX - (1 << b)); }
inline void _unsetbit(int &x, int b) { x = unsetbit(x, b); }
inline int countbit(int x) {
  x = x - ((x >> 1) & 0x55555555);
  x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
inline long long countbit(long long x) {
  int p1 = (x >> 32) & ((1ll << 32) - 1);
  int p2 = x & ((1ll << 32) - 1);
  return countbit(p1) + countbit(p2);
}
template <typename T>
void printbit(T x, int len) {
  for (int i = len - 1; i >= 0; i--) printf("%d", getbit(x, i));
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
template <typename A, typename B>
ostream &operator<<(ostream &stream, const pair<A, B> &p) {
  stream << "{" << p.first << "," << p.second << "}";
  return stream;
}
template <typename A>
ostream &operator<<(ostream &stream, const vector<A> &v) {
  stream << "[";
  for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr << " ";
  stream << "]";
  return stream;
}
template <typename A, typename B>
ostream &operator<<(ostream &stream, const map<A, B> &v) {
  stream << "[";
  for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr << " ";
  stream << "]";
  return stream;
}
template <typename A>
ostream &operator<<(ostream &stream, const set<A> &v) {
  stream << "[";
  for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr << " ";
  stream << "]";
  return stream;
}
template <typename A>
ostream &operator<<(ostream &stream, const stack<A> &v) {
  stack<A> st = v;
  stream << "[";
  while (!st.empty()) {
    stream << st.top() << " ";
    st.pop();
  }
  stream << "]";
  return stream;
}
template <typename A>
ostream &operator<<(ostream &stream, const priority_queue<A> &v) {
  priority_queue<A> q = v;
  stream << "[";
  while (!q.empty()) {
    stream << q.top() << " ";
    q.pop();
  }
  stream << "]";
  return stream;
}
template <typename A>
ostream &operator<<(ostream &stream, const queue<A> &v) {
  queue<A> q = v;
  stream << "[";
  while (!q.empty()) {
    stream << q.front() << " ";
    q.pop();
  }
  stream << "]";
  return stream;
}
void run();
int main() {
  srand(time(NULL));
  do {
    run();
    if (0) {
      0 ? printf("-------------------------------\n") : 0;
      0 ? printf("-------------------------------\n") : 0;
      0 ? break_point() : 0;
    }
  } while (0);
  return 0;
}
const int mod = 1e9 + 7;
const long long INF = 1e12;
struct Point {
  int x, y;
  Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
  long long dist(const Point &other) const {
    return abs(x - other.x) + abs(y - other.y);
  }
};
long long dp[305][305];
int a[305][305];
long long d[305][305];
int TM = 1;
int u[305][305];
vector<Point> g[100005];
int dt[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
void run() {
  int n, m, p;
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      read_integer(a[i][j]);
      g[a[i][j]].push_back(Point(i, j));
      dp[i][j] = a[i][j] == 1 ? i + j : INF;
    }
  }
  sort(g[1].begin(), g[1].end(), [](const Point &a, const Point &b) {
    return dp[a.x][a.y] < dp[b.x][b.y];
  });
  for (int curp = 2; curp <= p; ++curp) {
    if (((int)g[curp - 1].size()) * ((int)g[curp].size()) > n * m) {
      TM++;
      queue<Point> q;
      q.push(g[curp - 1][0]);
      u[q.front().x][q.front().y] = TM;
      d[q.front().x][q.front().y] = dp[q.front().x][q.front().y];
      int ptr = 1;
      while (ptr < ((int)g[curp - 1].size()) &&
             d[q.front().x][q.front().y] ==
                 dp[g[curp - 1][ptr].x][g[curp - 1][ptr].y]) {
        u[g[curp - 1][ptr].x][g[curp - 1][ptr].y] = TM;
        d[g[curp - 1][ptr].x][g[curp - 1][ptr].y] =
            dp[g[curp - 1][ptr].x][g[curp - 1][ptr].y];
        q.push(g[curp - 1][ptr]);
        ptr++;
      }
      while (!q.empty()) {
        Point cur = q.front();
        q.pop();
        while (ptr < ((int)g[curp - 1].size()) &&
               d[cur.x][cur.y] + 1 ==
                   dp[g[curp - 1][ptr].x][g[curp - 1][ptr].y]) {
          u[g[curp - 1][ptr].x][g[curp - 1][ptr].y] = TM;
          d[g[curp - 1][ptr].x][g[curp - 1][ptr].y] =
              dp[g[curp - 1][ptr].x][g[curp - 1][ptr].y];
          q.push(g[curp - 1][ptr]);
          ptr++;
        }
        for (int t = 0; t < 4; ++t) {
          int x = cur.x + dt[t][0];
          int y = cur.y + dt[t][1];
          if (x >= 0 && x < n && y >= 0 && y < m) {
            if (u[x][y] != TM) {
              d[x][y] = INF;
              u[x][y] = TM;
            }
            if (d[x][y] > d[cur.x][cur.y] + 1) {
              d[x][y] = d[cur.x][cur.y] + 1;
              q.push(Point(x, y));
            }
          }
        }
      }
      for (int i = 0; i < ((int)g[curp].size()); ++i) {
        Point &cur = g[curp][i];
        dp[cur.x][cur.y] = d[cur.x][cur.y];
      }
    } else {
      for (int i = 0; i < ((int)g[curp].size()); ++i) {
        Point &cur = g[curp][i];
        for (int j = 0; j < ((int)g[curp - 1].size()); ++j) {
          Point &prv = g[curp - 1][j];
          dp[cur.x][cur.y] =
              min((dp[cur.x][cur.y]), (dp[prv.x][prv.y] + cur.dist(prv)));
        }
      }
    }
    sort(g[curp].begin(), g[curp].end(), [](const Point &a, const Point &b) {
      return dp[a.x][a.y] < dp[b.x][b.y];
    });
  }
  long long res = LLONG_MAX;
  for (int i = 0; i < ((int)g[p].size()); ++i)
    res = min((res), (dp[g[p][i].x][g[p][i].y]));
  printf(0 ? "%lld" : "%I64d", res);
  putchar('\n');
}
