import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.range;

void main() {
	readln;
	auto a = readln.chomp.split(" ").map!(to!int).array.to!(int[]);
	size_t y = size_t.max;
	foreach(n; (a.reduce!min)..(a.reduce!max)) {
		size_t fn = 0;
		foreach (x; a) {
			fn += n % x;
		}
		y = min(y, fn);
	}
	y.writeln;
}
