Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = io.NextInt()
		}
		ans := 0
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] <= m {
					ans = intMax(a[i]+a[j], ans)
				}
			}
		}
		if ans == 0 {
			io.Println("NONE")
		} else {
			io.Println(ans)
		}
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <iostream>
using namespace std;
int main(void){
    int n, m, a[1010];
    while(cin >> n >> m){
        int max = 0;
        if(n == 0&& m==0)    break;
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                if(a[i]+a[j]<=m && max<a[i]+a[j]){
                    max = a[i]+a[j];
                }
            }
        }
        if(max == 0)    cout << "NONE" <<endl;
        else    cout << max << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;

int main(){
	int n,m,a[1000],dp[1001],b=0;
	dp[0]=0;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=1;i<=n;i++){
			dp[i]=max(dp[i-1],b+a[i-1]);
			b=max(b,a[i-1]);
		}
		cout<<dp[n-1]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
    long long n,m,a[1000],ans,num;
    cin >> n >> m;
        num=0;
        ans=0;
        if(n==0&&m==0)  break;
    for(int i=0;i<n;i++)    cin >> a[i];
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            num = a[i]+a[j];
            if(num<=m)
            ans = max(ans,num);
        }
    }
        if(ans==0)  cout <<"NONE"<<endl;
        else    cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <fstream>

using namespace std;
ifstream fin("date.in");

int a[1001], n, m, k, sumaMax;

void interschimbare(int poz1,int poz2,int vect[])
{
    if(vect[poz1]>vect[poz2]) swap(vect[poz1],vect[poz2]);
}

void interclasare(int poz1,int poz2,int poz3,int vect[])
{
    int v[10001]={0},nrElemente=0;
    int i=poz1,j=poz2;
    while(i<=poz2 && j<=poz3)
        {
         if(vect[i]<vect[j]) v[++nrElemente]=vect[i++];
          else v[++nrElemente]=vect[j++];
        }
    while(i<poz2) v[++nrElemente]=vect[i++];
    while(j<poz3) v[++nrElemente]=vect[j++];

    for(int i=poz1;i<=poz3;++i) vect[i]=v[i];
}

void mergeSort(int li,int ls,int vect[])
{
    if((ls-li)<2) interschimbare(li,ls,vect);
     else{
          int mij=(li+ls)/2;
          mergeSort(li,mij,vect);
          mergeSort(mij+1,ls,vect);
          interclasare(li,mij,ls,vect);
         }
}

int main()
{
    while(1)
    {
    cin>>n>>m;
    if(n==0 && m==0)
        return 0;
    for(k=1; k<=n; ++k)
        cin>>a[k];

    //mergeSort(1,n,a);
    for(int i=1; i<n; ++i)
        {
         for(int j=i+1;j<=n;++j)
            {
             if(a[i]>a[j]) swap(a[i],a[j]);
            }
        }
    int i=1, j=n;
    sumaMax=-1;

    while(i<j)
    {
        if(a[i]+a[j]<=m)
            {
                sumaMax=max(sumaMax,a[i]+a[j]);
                i++;
            }
        else if(a[i]+a[j]>m)
            j--;
    }
    if(sumaMax==-1)
        cout<<"NONE\n";
    else
        cout<<sumaMax<<'\n';
    }
    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main(){

    for(int n, m; cin >> n >> m, n;){
        vll A(n);
        ll ans = -1;
        for(int i = 0; i < n; i++)cin >> A[i];
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                if(A[i] + A[j] <= m)ans = max(ans, A[i]+A[j]);
            }
        }
        if(ans < 0)cout <<"NONE"<<endl;
        else cout << ans << endl;
    }    

    return 0;
}

C++: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, m;

void solve(){
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    int ans = -1;
    rep(i, n)For(j, i + 1, n){
        if(a[i] + a[j] <= m) chmax(ans, a[i] + a[j]);
    }
    if(ans < 0) puts("NONE");
    else printf("%d\n", ans);
}

int main(){
    while(scanf("%d%d", &n, &m) && n){
        solve();
    }
}

C++: #include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e3 + 5;
int a[maxn];
int n, m;
set<int>s;

int main() {
	while (scanf("%d %d", &n, &m)) {
		s.clear();
		if (n == 0 && m == 0)break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		int max = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if(i!=j) s.insert(a[i] + a[j]);
			}
		}
		//set<int>::iterator it = s.upper_bound(m);
		bool flag = false;
		for (set<int>::iterator it = --s.end(); it != s.begin(); it--) {
			if (*it <= m) {
				printf("%d\n", *it);
				flag = true;
				break;
			}
		}
		if (!flag) {
			if (*s.begin() <= m) printf("%d\n", *s.begin());
			else printf("NONE\n");
		}
	}
	return 0;
}