#!/usr/bin python3
import sys
import random

n = int(sys.stdin.readline())
t = [int(sys.stdin.readline()) for _ in range(n)]
t.reverse()

dp = [[[0] * 10 for _ in range(10)] for _ in range(2 * n)]

for a in range(10):
  if a < t[0]:
    dp[0][a][0] = 1
for b in range(10):
  for a in range(10):
    if 10 * b + a < t[0]:
      dp[1][b][a] = 1
for i in range(2, n * 2):
  ct, pt = t[i // 2], t[(i - 1) // 2] if i % 2 == 0 else t[i // 2 - 1]
  for a in range(10):
    for b in range(10):
      pre = dp[i - 1][b][a]
      if pre == 0: continue
      for c in range(10):
        if i % 2 == 0:
          if c * 10 + max(a, b) >= pt or c >= ct: continue
        else:
          if c * 10 + b >= ct: continue
        dp[i][c][b] += pre
ans = 0
for i in range(n * 2):
  for b in range(1, 10):
    for a in range(10):
      ans += dp[i][b][a]
total, prev = 0, 1
for i in range(n):
  total += prev * (t[i] - 1)
  prev *= t[i]
print (total - ans)
