#include <bits/stdc++.h>
using namespace std;
int INF = 1 << 32;
int N, A, B, C;
int min(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
int rec(vector<int> l, int i, int a, int b, int c) {
  if (i == N) {
    if (!a || !b || !c) {
      return INF;
    }
    return abs(A - a) + abs(B - b) + abs(C - c);
  }
  int res = rec(l, i + 1, a, b, c);
  res = min(res, rec(l, i + 1, l[i], b, c) + (a ? 10 : 0));
  res = min(res, rec(l, i + 1, a, l[i], c) + (b ? 10 : 0));
  res = min(res, rec(l, i + 1, a, b, l[i]) + (c ? 10 : 0));
  return res;
}
int main() {
  int n, a, b, c;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  int res = rec(v, 0, 0, 0, 0);
  cout << res;
  return 0;
}
