Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

deque<char> plus1(deque<char> const& a) {

  if(a == deque<char>{'0'}) { return {'1'}; }

  deque<char> ret; ret.push_back('0');
  copy(a.begin(), a.end(), back_inserter(ret));
  ret.back() += 1;
  int N = ret.size();
  int idx = N-1;
  while(ret[idx] == '9' + 1) {
    ret[idx] = '0';
    ret[--idx] += 1;
  }

  deque<char> ans;
  bool ok = false;
  REP(i, 0, N) {
    if(ok || (ret[i] != '0')) {
      ok = 1;
      ans.push_back(ret[i]);
    }
  }

  return ans;
}

deque<char> zeroclear(deque<char>& s) {
  deque<char> ret;
  bool ok = false;
  rep(i, s.size()) {
    if(ok || s[i] != '0') {
      ok = 1;
      ret.push_back(s[i]);
    }
  }
  if(ret.empty()) { ret.push_back('0'); ; }
  return ret;
}
struct comp {
bool operator() (deque<char> const& a, deque<char> const& b) {
  int asize = a.size(), bsize = b.size();
  if(asize != bsize) { return asize < bsize; }
  for(int i=0; i<asize; i++) {
    if(a[i] != b[i]) {
      return a[i] < b[i];
    }
  }
  return 0;
}
};

int main() {

  int N; cin >> N;
  string S;
  rep(i, N) {
    char ch; cin >> ch;
    S.push_back(ch);
  }

  set<deque<char>, comp> vs;
  rep(i, N) {
    deque<char> s;
    REP(j, i, N) {
      if(j - i > 7) { continue; }
      s.push_back(S[j]);
      vs.insert(zeroclear(s));
    }
  }

//  int cc = 0;
//  for(auto& s: vs) { if(++cc >= 15) { break; } rep(i, s.size()) { cout << s[i]; } cout << endl; }cout << endl;
//  rep(i, v.size()) {  cout << v[i] << endl; }cout << endl;

  deque<char> curr; curr.push_back('0');
  for(auto& s: vs) {
    if(curr != s) {
      rep(i, curr.size()) { cout << curr[i]; }
      cout << endl;
      exit(0);
    }
    curr = plus1(curr);
//    cout << "---\n";   cout << curr << endl;
  }

  rep(i, curr.size()) { cout << curr[i]; }
  cout << endl;

  return 0;
}

Compiler output:
In file included from /usr/include/c++/14/set:62,
                 from a.cc:8:
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = std::deque<char>; _Val = std::deque<char>; _KeyOfValue = std::_Identity<std::deque<char> >; _Compare = comp; _Alloc = std::allocator<std::deque<char> >; _Const_Link_type = const std::_Rb_tree_node<std::deque<char> >*]':
/usr/include/c++/14/bits/stl_tree.h:2116:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = std::deque<char>; _Val = std::deque<char>; _KeyOfValue = std::_Identity<std::deque<char> >; _Compare = comp; _Alloc = std::allocator<std::deque<char> >; key_type = std::deque<char>]'
 2116 |           __comp = _M_impl._M_key_compare(__k, _S_key(__x));
      |                                                ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:2169:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = std::deque<char>; _Key = std::deque<char>; _Val = std::deque<char>; _KeyOfValue = std::_Identity<std::deque<char> >; _Compare = comp; _Alloc = std::allocator<std::deque<char> >]'
 2169 |         = _M_get_insert_unique_pos(_KeyOfValue()(__v));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:523:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = std::deque<char>; _Compare = comp; _Alloc = std::allocator<std::deque<char> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::deque<char>, std::deque<char>, std::_Identity<std::deque<char> >, comp, std::allocator<std::deque<char> > >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<std::deque<char> >; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<std::deque<char> >, std::deque<char> >::rebind<std::deque<char> >; typename _Alloc::value_type = std::deque<char>; value_type = std::deque<char>]'
  523 |           _M_t._M_insert_unique(std::move(__x));
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:91:16:   required from here
   91 |       vs.insert(zeroclear(s));
      |       ~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:768:15: error: static assertion failed: comparison object must be invocable as const
  768 |               is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:768:15: note: 'std::is_invocable_v<const comp&, const std::deque<char, std::allocator<char> >&, const std::deque<char, std::allocator<char> >&>' evaluates to false