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 <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
auto constexpr infty<int> = 1'100'100'100;
template<>
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

int main() {
  // cout << fixed << setprecision(10);

  int N, M;
  while (cin >> N >> M && N + M > 0) {
    vector<int> vals;
    REP(i, N) {
      int A;
      cin >> A;
      vals.push_back(A);
    }
    int ans = -1;
    REP(i, N) REP(j, N) {
      int price = vals[i]+vals[j];
      if (i == j || price > M) { continue; }
      chmax(ans, price);
    }
    if (ans == -1) {
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> p;

int main()
{
  while(true){
    ll n, m;
    ll res = 0;
    cin >> n >> m;
    vector<ll> v(n, 0);
    if (n == 0 && m == 0) {
      return 0;
    }
    for (int i = 0; i < n; i++){
      cin >> v[i];
    }

    for (int i = 0; i < n; i++){
      for (int j = i+1; j < n; j++){
        if (v[i] + v[j] <= m && res <= v[i] + v[j]) {
          res = v[i] + v[j];
        }
      }
    }
    if (res == 0) {
      cout << "NONE" << endl;
    }else{
      cout << res << endl;
    }
  }
}

C++: #include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int n,m,a[1000];

map<int,int> c;

int main() {
    while(true) {
        cin >> n >> m;
        if(n == 0)break;
        rep(i,n){
            cin >> a[i];
            c[a[i]] = 0;
        }
        rep(i,n) {
            c[a[i]]++;
        }
        sort(a,a+n);//aをソート

        int ans = -1;
        rep(i,n) {
            auto itr = upper_bound(a,a+n,m - a[i]);//m-a[i]<a[j] となる最小のjのa[j]へのポインタを取得
            if(itr - a == 0) {//m - a[i]>=a[j]を満たすjが存在しない時
                continue;
            }
            itr--;//ポインタを一つ減算してm-a[i]>=a[j]となる最大のjのa[j]へのポインタを取得
            if(*itr == a[i] && c[a[i]] < 2) {//境界のものがa[i]だった時
                if(itr - a == 0) {//a[i]未満のものがない時
                    continue;
                }
                itr--;//さらに一つ前に
            }
            ans = max(ans,*itr + a[i]);
        }
        if(ans == -1)cout << "NONE" << endl;
        else cout << ans << endl;
    }

    return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n,m;
    while(cin>>n>>m, n || m){
        int res = 0;
        vector<int> a(n);
        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) continue;
                res = max(res, a[i] + a[j]);
            }
        }
        if(res==0){
            cout<<"NONE"<<endl;
        }
        else{
            cout<<res<<endl;
        }
    }
}

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

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

C++: #include <iostream>

using namespace std;

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

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

int main(){

    int n,m,price,sum,temp_sum;
    sum=0;
    std::vector<int> prices;

    std::cin>>n>>m;

    for(int i=0;i<n;i++){
        std::cin>>price;
        prices.push_back(price);
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            temp_sum = prices[i]+prices[j];
            if(sum<temp_sum&&temp_sum<m) sum=temp_sum;
        }
    }

    if(sum==0){
        std::cout<<"NONE"<<std::endl;
    }
    else{
        std::cout<<sum<<std::endl;
    }

    return 0;

}