using LIB; using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { static int n; static int[] m; static int total(int i) { int ret = 0; for (int j = 0; j < i; j++) { ret += m[j]; } return ret % 1000; } static void Main(string[] args) { n = io.r(); m = io.r(n); int output = 0; for (int i = 0; i < n; i++) { if (i > 0) { output += Math.Max(0, m[i] - total(i)); } else { output += m[i]; } } io.w(output); io.wflush(); } } namespace LIB { public class io { private const int WMAX = 1000; private static StringBuilder S = new StringBuilder(); public static T r() { return util.parse(r()); } public static T[] r(char s = ' ') { return r().Split(s).Select(util.parse).ToArray(); } public static T[] r(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r(); } return r; } public static T[][] r(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r(s); } return r; } private static string r() { return Console.ReadLine(); } public static void w(object v, bool lf = true) { S.Append(util.parse(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } } public static void wflush() { Console.Write(S.ToString()); S.Length = 0; } } public class util { public static T parse(object value) { return (T)(Convert.ChangeType(value, typeof(T))); } } public class memo { private Dictionary R; public memo() { R = new Dictionary(); } public Result exec(Key k, Func f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; } } }