import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int n2 = n * 2; long[] a = new long[n2 + 1]; for (int i = 1; i <= n; i++) { a[i] = sc.nextInt(); a[i + n] = a[i]; } sc.close(); long ans = 0; long val = 0; int r = 0; for (int l = 0; l <= n; l++) { while (r < n2 && r - l < n - 1 && val <= x) { r++; val += a[r]; if (val <= x) { ans = Math.max(ans, val); } else { break; } } val -= a[l]; if (val <= x) { ans = Math.max(ans, val); } } System.out.println(ans); } }