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 <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	int N,M;
	for(;~scanf("%d%d",&N,&M)&&N&&M;){
		int R=-1;
		vector<int>v(N);
		for(int i=0;i<N;i++){
			scanf("%d",&v[i]);v[i]=-v[i];
		}
		sort(v.begin(),v.end());
		for(int i=0;i<N;i++){
			int idx=distance(v.begin(),lower_bound(v.begin(),v.end(),-M-v[i]));
			if(idx==i)idx++;
			if(idx<N)R=max(R,-v[i]-v[idx]);
		}
		printf(R<0 ? "NONE\n" : "%d\n", R);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,m;
	while(cin>>n>>m,n){
	    vi a(n);
	    int ans=-1;
		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]);
		    }
		}
		if(ans==-1)cout<<"NONE"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int maxn = 1001;
long long a[maxn];
long long n,m; 

int main(){
	while(scanf("%d%d",&n,&m)==2&&n!=0&&m!=0){
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		long long tot=0,ans=-1;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j) continue;
				tot = a[i]+a[j];
				if(tot<=m&&tot>ans){
					ans=tot;
				}
			}
		}
		if(ans>=0)printf("%d\n",ans);
		else printf("NONE\n");
	}
} 

/*
3 45
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0
*/

C++: #include <iostream>
#define N 100000

int main(){
  int n=1,max;
  int A[N]={0},k=0;


  while(n!=0){
    int p=0,tmp;
    std::cin>>n;
    int a[n]={0};
    std::cin>>max;
    if(n==0)break;
    for(int i=0;i<n;i++){
      std::cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	tmp=a[i]+a[j];
	if(tmp>=A[k]&&tmp<=max){
	  A[k]=tmp;
	  p++; 
	}
      }
    }
    if(p==0) A[k]=0;

      k++;
    //if(p!=0) std::cout<<sum<<"\n";
    //else std::cout<<"NONE\n";
  }
  for(int i=0;i<k;i++){
    if(A[i]!=0){
      std::cout<<A[i]<<"\n";
    }else{
      std::cout<<"NONE\n";
    }
   
  }



}

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

const int maxn = 1000 + 5;
int n, m;
int mem[maxn];

bool Input()
{
	cin >> n >> m;
	if(!n && !m) return false;
	for(int i = 0; i < n; i++)
	{
		cin >> mem[i];
	}
	return true;
}

int solve()
{
	sort(mem, mem+n);
	int ans = -1, tmp;
	for(int i = n-1; i >= 0; i--)
		for(int j = i-1; j >= 0; j--)
		{
			//cout << mem[i] << " " << mem[j] << endl;
			tmp = mem[i]+mem[j];
			if(tmp > ans && tmp <= m) ans = tmp;
		}
	if(ans >= 0) return ans;
	return -1;
}

void Init()
{
	memset(mem, 0, sizeof(0));
}

int main()
{
	while(1)
	{
		Init();
		if(!Input()) break;
		int res = solve();
		if(res >= 0) printf("%d\n", res);
		else printf("NONE\n");
	}
}