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>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    while(cin >> n >> m, n|m){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        int ans = -1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if(i == j) continue;
                if(ans <= v[i]+v[j] && v[i]+v[j] <= m) ans = v[i]+v[j];
            }
        }
        if(ans == -1) puts("NONE");
        else cout << ans << "\n";
    }
    return 0;
}

C++: #include<iostream>
int main()
{
  int n,m,k=0;
  int a[100000];
  int ans[50000]={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>
using namespace std;

int main() {
	int n, m;
	while(1){
		cin >> n >> m;
		if(n==0 && m==0) break;
		int p[1000], sum, max=0;
		for(int a=0; a<n; a++)
			cin >> p[a];
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				sum = p[i]+p[j];
				if(max<sum && sum<=m) max = sum;
			}
		}
		if(max==0) cout << "NONE" << endl;
		else cout << max << endl;
	}
	return 0;
}

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

int main() {
  int n, m;
  vector<int> a;
  int flag = 0;


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

    for (int i = 0; i < n; i++) {
      int A;
      cin >> A;
      a.push_back(A);
    }

    vector<int> sum;

    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(i != j) {
          int Sum = a[i] + a[j];
          sum.push_back(Sum);
        }
      }
    }

    sort(sum.begin(), sum.end(), greater<int>());

    for(int i = 0; i < sum.size(); i++){
      if(sum[i] <= m) {
          cout << sum[i] << endl;
          flag = 1;
          break;
      }
    }

    if(flag == 0) {
      cout << 'N' << 'O' << 'N' << 'E' << endl;
    }

    sum.clear();
    a.clear();
  }
  return 0;
}

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

int a[1010];
int n, m;
int main(){
  while(true){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    for(int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;
    int tmp = 0;
    for(int i = 0; i < n; i++){
      for (int j = i + 1; j < n; j++){
        tmp = a[i] + a[j];
        if(tmp <= m){
          ans = max(ans, tmp);
        }
      }
    }
    if(ans == 0){
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
}

C++: #include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {

	int n, m;

	while (cin >> n >> m, n != 0 && m != 0) {
		vector<int>v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i];
		}
		int ans = -1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j && max(ans, v[i] + v[j]) <= m) {
					ans = max(ans, v[i] + v[j]);
				}
			}
		}
		if (ans == -1) {
			cout << "NONE" << endl;
		}
		if (ans != -1) {
			cout << ans << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int n,m,a[1024]={},ans=0;
signed main(){
  while(1){
    cin >> n >> m;
    ans=0;
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        if(a[i]+a[j]<=m) chmax(ans,a[i]+a[j]);
      }
    }
    if(ans==0) cout << "NONE"<< endl;
    else cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

int main(){
    int n, m;
    while(1){
        cin >> n >> m;
        if(n + m == 0) break;
        vector<int> a(n);
        rep(i, 0, n) cin >> a[i];
        int ans = -1;
        rep(i, 0, n){
            rep(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;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int n, m;
int nums[1000+10];

int find(int L, int R, int vl)
{
	int l = L, r = R;
	int mid = 0;
	while(l < r)
	{
		mid = (l+r) / 2;
		if(nums[mid] < vl)
			l = mid+1;
		else
			r = mid;
	}
	return l;
}

int main()
{
	while(true)
	{
		scanf("%d%d", &n, &m);
		if(!n && !m)
			break;
		for(int i = 0 ;i < n; i++)
		{
			scanf("%d", &nums[i]);
		}
		sort(nums, nums+n);
		int ans = 0;
		for(int i = n-1; i >= 0; i--)
		{
			if(nums[i] >= m)
				continue;
//			int pos = lower_bound(nums, nums+n, m-nums[i]) - nums;
			int pos = find(0, n-1, m-nums[i]);
			for(int j = pos; j >= 0; j--)
			{
				if(m-nums[i] >= nums[j] && i != j)
				{
					pos = j;
					break;
				}
			}
			if(i == pos)
				break;
			int tmp = nums[pos];
			if(tmp+nums[i] <= m)
				ans = max(ans, nums[i]+tmp);
		}
		if(ans)
			printf("%d\n", ans);
		else
			printf("NONE\n");
	}
	return 0;
}