#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <complex>
#include <ctime>
#include <cassert>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define REP(i,s,t) for(int i=(s);i<(t);i++)
#define FILL(x,v) memset(x,v,sizeof(x))

const int INF = (int)1E9;
#define MAXN 10

ll dp[MAXN * 2][10][10];
int t[MAXN];
int main() {
  int n;
  cin >> n;
  REP(i,0,n) cin >> t[i];
  reverse(t, t + n);
  REP(a,0,10) if (a < t[0]) dp[0][a][0] = 1;
  REP(b,0,10) REP(a,0,10) if (10 * b + a < t[0]) dp[1][b][a] = 1;
  REP(i,2,n*2) {
    int ct = t[i / 2], pt = i % 2 == 0 ? t[(i - 1) / 2] : t[i / 2 - 1];
    REP(a,0,10) {
      REP(b,0,10) {
        ll pre = dp[i - 1][b][a];
        if (pre == 0) continue;
        REP(c,0,10) {
          if (i % 2 == 0) {
            if (c * 10 + max(a, b) >= pt || c >= ct) continue;
          } else {
            if (c * 10 + b >= ct) continue;
          }
          dp[i][c][b] += pre;
        }
      }
    }
  }
  ll ans = 0;
  REP(i,0,n*2) REP(b,1,10) REP(a,0,10) ans += dp[i][b][a];
  ll total = 0, prev = 1;
  REP(i,0,n) {
    total += (t[i] - 1) * prev;
    prev *= t[i];
  }
  cout << total - ans << endl;
  return 0;
}
