public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = in.readLine();
		int n = Integer.parseInt(line);
		int arr[] = atoi(in.readLine());
		int i = 0;
		int res = 0;

		ArrayList<Integer> lista = new ArrayList<Integer>();
		for (int j = 0; j < arr.length; j++) {
			if (arr[j] == 1)
				for (int k = j + 1; k < arr.length; k++) {
					if (arr[k] == 1) {
						lista.add(k - j);
						break;
					}
				}
		}

		if (lista.size() > 0) {
			res++;
		}
		for (int j = 0; j < lista.size(); j++) {
			if (lista.get(j) == 1)
				res++;
			else if (lista.get(j) == 2) {
				res += 2;
			} else {
				res += 2;
			}

		}

		System.out.println(res);
	}