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>
int main()
{
  int n,m,k=0;
  int a[1000];
  int ans[1000]={0};
  int max;

  while(n>0 && m>0){
    std::cin>>n>>m;
    if(n==0 && m==0) break;
    for(int i=0;i<n;i++){
      std::cin>>a[i];
    }
    max=0;
    for(int i=0;i<n-1;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];
	}
      }
    }
    ans[k]=max;
    k++;
  }
  for(int i=0;i<k;i++){
    if(ans[i]!=0){
      std::cout<<ans[i]<<'\n';
    }else{
      std::cout<<"NONE"<<'\n';
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  vector<int> a;
  int n,m,b,max=0;
  while(n!=0 && m!=0){
    max=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
      cin>>b;
      a.push_back(b);
    }
  
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	if(j!=k){
	  if(max<a[j]+a[k] && a[j]+a[k]<=m){
	    max=a[j]+a[k];
	    //cout<<max;
	  }
	}
      }
    }
    if(max==0 && n!=0&&m!=0){
      cout<<"NONE"<<endl;
    }else if(n!=0&&m!=0){
      cout<<max<<endl;
    }
  }
}

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

int main(){

  while(1){
    int n, m; cin >> n >> m;
    if(!n) break;

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

    vector<int> b;
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
	b.push_back(a[i] + a[j]);
      }
    }


    int ans = -1;
    for(auto x : b){
      if(x <= m) ans = max(ans, x);
    }

    if(ans == -1) cout << "NONE" << endl;
    else cout << ans << endl;

  }

  return 0;
}

C++: #include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
 
using namespace std;
 
int main() {
  int n,m;
  while( cin >> n >> m, n|m ) {
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    int maxi = -1;
    rep(i,n) {
      int rem = m - a[i];
      int ptr = upper_bound(ALL(a),rem) - a.begin();
      --ptr;
      if( ptr == i ) --ptr;
      if( ( 0 <= ptr && ptr < n ) && a[i] + a[ptr] <= m ) maxi = max(maxi,a[i]+a[ptr]);
    }
    ( maxi == -1 ) ? puts("NONE") : printf("%d\n",maxi);
  }
  return 0;
}

C++: #include<vector>
#include<list>
#include<map>
#include<climits>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<ctime>
#include<queue>
#include<random>
#include<cctype>


using namespace std;

typedef long long ll;
typedef long long LL;

typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {

    while (true)
    {

        int L, Max;
        cin >> L >> Max;
        
        if (L == 0 && Max == 0)
            break;


        VI d(L);
        for (auto& i : d) cin >> i;


        int result = -1;
        for (int i{}; i < L; ++i)
        {
            for (int j{}; j < L; ++j)
            {
                if (i == j) continue;

                auto current = d[i] + d[j];
                if (result < current && current <= Max)
                    result = current;
            }
        }

        if (result == -1)
            cout << "NONE";
        else
            cout << result;
    }

}

C++: #include<iostream>
int maxs(int n,int m,int a[]){
  int maxs=0,flag=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){

      if(maxs<a[i]+a[j]){
	if(a[i]+a[j]<=m){
	  maxs=a[i]+a[j];
	  flag=1;
	}
      }

    }
  }

  if(flag==1){
    return maxs;
  }else{
    return -1;
  }
}


int main(){

  int n,m,count=0;
  int b[50000];
  int a[1000];
  while(n!=0&&m!=0){
    std::cin>>n;
    std::cin>>m;
    if(n==0&&m==0){
      break;
    }
    for(int i=0;i<n;i++){
      std::cin>>a[i];
    }
    b[count]=maxs(n,m,a);
    count++;
  }
  for(int i=0;i<count;i++){
    if(b[i]==-1){
      std::cout<<"NONE"<<"\n";
    }else{
      std::cout<<b[i]<<"\n";
    }
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  vector<int> a(1000);
  int n,m,b,max=0;
  while(n!=0 && m!=0){
    max=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
      cin>>b;
      a[i]=b;
    }
  
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	if(j!=k){
	  if(max<a[j]+a[k] && a[j]+a[k]<=m){
	    max=a[j]+a[k];
	    //cout<<max;
	  }
	}
      }
    }
    if(max==0 && n!=0&&m!=0){
      cout<<"NONE\n";
    }else if(n!=0&&m!=0){
      cout<<max<<"\n";
    }
  }
}

C++: n, m = map(int, input().split())
while n != 0 and m != 0:
    a = list(map(int, input().split()))
    dp = []
    for i in range(n):
        for j in range(n):
            if a[i]+a[j]<= m and i != j:
                dp.append(a[i]+a[j])
    if len(dp) == 0:
        print("NONE")
    else:
        print(max(dp))
    n, m = map(int, input().split())

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);
    int ans = 0;
    if (a[n - 1] + a[n - 2] < m) {
      cout << a[n - 1] + a[n - 2] << endl;
      continue;
      }
    for (int i = 0; i < n; i++) {
      int p = lower_bound(a, a + n, m - a[i]) - a;
      if (a[i] + a[p] > m)
        p--;
      if (i == p)
        p--;
      if (p < 0) continue;
      if (a[i] + a[p] > ans)
        ans = a[i] + a[p];
    }
    if (ans)
        cout << ans << endl;
    else
        cout << "NONE" << endl;
  }
}