#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int n, res, w[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d",w + i);
for (int i = 2; i <= n; i++)
if (w[i] > w[i-1])
res += w[i] - w[i-1];
printf("%d\n", res);
return 0;
}