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 <bits/stdc++.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int n,m,a[1000];
int ans;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>n>>m;
	REP(i,n) cin>>a[i];

	REP(i,n) REP(j,i) if(a[i]+a[j]<=m) ans=max(ans,a[i]+a[j]);
	cout<<ans<<endl;

	return 0;
}

C++: #include<bits/stdc++.h>
#define MAX 1001
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main()
{
  int n,m,a[MAX];
  while(cin>>n && cin>>m && n){
    int ans = -1;
    FOR(i,0,n)cin>>a[i];
    FOR(i,0,n)
      FOR(j,i+1,n)
        if(a[i]+a[j]<=m)ans=max(ans,a[i]+a[j]);
    if(ans==-1)cout<<"NONE"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF&&n!=0)
	{
		int  f[1500]={0};
		bool flag=false;
		for(int i=0;i<n;i++)
		scanf("%d",&f[i]);
		sort(f,f+n);
		int l=0,r,ans=0;
		for(int i=0;i<n;i++)
		{
			int s=m-f[i];
			int j=lower_bound(f,f+n,s)-f;
			l=i,r=j;
			if(r>=n)
			r--;
			while(l<r)
			{
				if(f[l]+f[r]<=m)
				{
					flag=true;
					//cout<<f[l]+f[r]<<endl;
					ans=max(ans,f[l]+f[r]);
					break;
				}
				else
				r--;
			}
		} 
		if(flag)
		printf("%d\n",ans);
		else
		printf("NONE\n");
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

signed main(){
	int n, m;
	while(cin >> n >> m, n||m){
		vector<int> a(n);
		cin >> a;

		vector<int> b;
		rep(i,a.size()){
			range(j,i + 1, a.size()){
				b.emplace_back(a[i] + a[j]);
			}
		}
		sort(all(b), greater<int>());

		if(b.back() > m){
			cout << "NONE" << endl;
		}else{
			rep(i,b.size()){
				if(b[i] <= m){
					cout << b[i] << endl;
					break;
				}
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    if (a[n - 1] + a[n - 2] < m) {
      cout << a[n - 1] + a[n - 2] << endl;
      continue;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int p = lower_bound(a, a + n, m - a[i]) - a;
      while (p >= 0 && (a[i] + a[p] > m || i == p))
        p--;
      if (p >= 0 && a[i] + a[p] > ans)
        ans = a[i] + a[p];
    }
    if (ans)
      cout << ans << endl;
    else
      cout << "NONE" << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

void Sort(int *x, int *y);

int main(){
    while(1){
        int n,m;    cin>>n>>m;
        if(n==0&&m==0)break;

        int a[n];   for(int i=0;i<n;i++)cin>>a[i];

        for(int i=1;i<n;i++){
            int j=i-1;

            int min=a[i];

            while(j>=0 && a[j]>min){
                swap(a[j],a[j+1]);
                j--;
            }
        }

        int sum=0;
        for(int i=n-1;i>0;i--){
            for(int j=i-1;j>=0;j--){
                //cout<<"a[i]="<<a[i]<<":"<<"a[j]="<<a[j]<<endl;

                if((a[i]+a[j])<=m && a[i]+a[j]>sum){
                    sum = a[i]+a[j];
                }
            }
        }

        if(sum>0)cout<<sum<<endl;
        else cout<<"NONE"<<endl;
    }
    return 0;
}


void Sort(int *x,int *y){
    int hoge;
    hoge=*x;
    *x=*y;
    *y=hoge;
}