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 <cstdio>

using namespace std;

int main(){
  int n, m;


  while(1){
    scanf("%d %d", &n, &m); 

    if(n == 0 && m == 0){
      break;
    }

    int a[n];
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);

    int max = 0;
    for(int i = 0; i < n-1; i++){
      for(int j = i+1; j < n; j++){
        int tmp = a[i] + a[j];
        if(tmp > max && tmp <= m)
          max = tmp;
      }
    }

    if(max != 0)
      cout << max << endl;
    else
      cout << "NONE" << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,m;
int main(void){
    while(1){
        int ans = 0;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        vector<int> a(n);
        for(int i = 0;i < n;i++) cin >> a[i];
        
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(i == j) continue;
                if(a[i]+a[j] <= m)ans = max(ans,a[i]+a[j]);
            }
        }
        if(ans == 0) cout << "NONE" << endl;
        else cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<stdio.h>
const int INF =100000000;
using namespace std;
int main(){
  int n, m, a[1000];
  while(true){
    cin>>n>>m;
    if(n==0 && m==0){
      break;
    }
    int card = 0, count = 0;
    for(int i = 0; i < n; i++){
      for(int k = i + 1; k < n; k++){
        card++;
      }
    }
    for(int i = 0; i < n; i++){
      cin>>a[i];
    }
    int sum[card];
    for(int i = 0; i < n; i++){
      for(int k = i + 1; k < n; k++){
        sum[count] = a[i] + a[k];
        count++;
      }
    }
    sort(sum, sum+card);
    for(int i = 0; i < card-1; i++){
      if(sum[0] > m){
        cout<<"NONE"<<endl;
        i = card + 1;
      }else{
      if(sum[i] <= m && sum[i+1] > m){
        cout<<sum[i]<<endl;
        i = card +1;
      }
     }
    }
    if(sum[card-1] <= m){
      cout<<sum[card-1]<<endl;
    }
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n, m, a[1000], mx;

int main() {
  while (scanf("%lld%lld", &n, &m), n) {
    for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
    mx = -1;
    for (ll i = 0; i < n; i++) for (ll j = i+1; j < n; j++) if (a[i] + a[j] <= m) mx = max(a[i]+a[j], mx);
    if (mx == -1) printf("NONE\n");
    else printf("%lld\n", mx);
  }
}

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];
  while(n!=0&&m!=0){
    std::cin>>n;
    std::cin>>m;
    if(n==0&&m==0){
      break;
    }
    int a[n];
    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 <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n, m;
int a[1000];

void solve() {
    rep(i,n) cin >> a[i];
    int ans = -1;
    rep(i,n) for (int j = i+1; j < n; j++) {
        if (a[i] + a[j] > m) continue;
        ans = max(ans, a[i]+a[j]);
    }
    if (ans == -1) cout << "NONE" << endl;
    else cout << ans << endl;
}

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
    cout.precision(20);
    cerr << fixed;
    cerr.precision(6);
#ifdef LOCAL
    //freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif  
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        solve();
    }
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

C++: #include<iostream>
#include<string>
#include<queue>
#include<utility>

using namespace std;

int main(){

  int n,m,l=0,ans[25000]={0};
  int a[1000]={0};

  while(n!=0 && m!=0){
    cin>>n>>m;
    //  cout<<n<<" "<<m<<endl;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  /* for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
  }
  */
  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[l]){
	  ans[l]=a[i]+a[j];
	}     
      
    }
  }

 
 
 
  l++;
  }
     

  for(int i=0;i<l-1;i++){
  if(ans[i]!=0){
    cout<<ans[i]<<endl;
  }else{
    cout<<"NONE"<<endl;
  }
  }


return 0;
}

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);

	while(true) {
		cin>>n>>m;
		if(n==0) break;
		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;
}