#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
typedef long long ll;
using std::cout;
const char endl = '\n';
std::string s, ss;
std::string maxstr;
std::string str[1010];
int maxsum = -1, flag, cnt, sum, arr[1010];
namespace sscio {
inline ll pull() {
ll sign = 1LL,res = 0LL;
char ch = getchar();
for (;!isdigit(ch);ch=getchar()) {
if (ch == '-') {
sign *= -1LL;
}
}
for (;isdigit(ch);ch=getchar()) {
res = (res << 3) + (res << 1) - '0' + ch;
}
return sign * res;
}
}
void test() {
for (int i = 0;i < cnt;i ++) {
cout << str[i] << ' ';
}
cout << '\n';
}
void solve() {
int n = sscio::pull();
for (int i = 0;i < n;i ++) {
str[i] = std::to_string(sscio::pull());
}
std::sort(str, str + n);
cout << std::stoi(str[n - 1]) - std::stoi(str[0]);
}
signed main() {
solve();
return 0 ^ 0;
}