
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

template <typename T>
int len(T args) { return args.size(); }

vector<string> split(string &s, const char &c)
{
    string buffer{""};

    vector<string> resultado;

    for (char caractere : s)
    {
        if (caractere != c)
        {
            buffer += caractere;
        }
        else
        {
            resultado.push_back(buffer);
            buffer = "";
        }
    }
    if (buffer != "")
    {
        resultado.push_back(buffer);
        buffer = "";
    }

    return resultado;
}

int main() {
  string linha;
  int v=-1, a=-1, b=-1, c=-1; 
  while(true){
        getline(cin, linha);

        if (linha == "0")
        {
            break;
        }

        vector<string> temp = split(linha, ' ');

        v = atoi(temp[0].c_str());
        a = atoi(temp[1].c_str());
        b = atoi(temp[2].c_str());
        c = atoi(temp[3].c_str());

 
        int resp = 0;
        if(v >= a || v >= b || v >= c) resp = 1;
        if(v >= (a + b) || v >= (a + c) || v >= (b + c)) resp = 2;
        if(v >= (a + b + c)) resp = 3;
        printf("%d\n", resp);
  }
}