Language: C++

#include <iostream>
#include <vector>

using namespace std;
vector<int > leftRange;

vector<int > GetNumberInDigits(int n)
{
	vector<int > res;
	while (n)
	{
		int d = n % 10;
		res.push_back(d);

		n /= 10;
	}
	reverse(res.begin(), res.end());
	return res;
}

bool IsNumberPresentInArray(int n, vector<int > digits)
{
	for (int i = 0; i < (int)digits.size(); i++)
	{
		if (n == digits[i])
		{
			return true;
		}

	}
	return false;
}

int FindFirstInvalidIndex(vector<int > number, vector<int > invalidDigits)
{
	for (int i = 0; i < (int)number.size(); i++)
	{
		if (IsNumberPresentInArray(number[i], invalidDigits))
		{
			return i;
		}

	}

	return number.size();
}

int ConvertArrayToNumber(vector<int > number)
{
	int res = 0;
	for (int i = 0; i < (int)number.size(); i++)
	{
		res = res * 10 + number[i];
	}
	return res;
}

int FindNextDigit(int n, vector<int > invalidDigits)
{
	while (true)
	{
		if (n > 9) n = 0;
		bool isValid = true;
		for (int i = 0; i < (int)invalidDigits.size(); i++)
		{
			if (invalidDigits[i] == n)
			{
				n++;
				isValid = false;
				break;
			}

		}

		if (isValid) return n;
	}
}

int FindNextMinDigit(int n, vector<int > invalidDigits)
{
	for (int j = 0; j <= 9; j++)
	{
		if (!IsNumberPresentInArray(j, invalidDigits))
		{
			return j;
		}
	}
}

void ProcessRightRange(vector<int > &number, int index, vector<int > invalidDigits)
{
	for (int i = index; i < (int)number.size(); i++)
	{
		number[i] = FindNextMinDigit(number[i], invalidDigits);
	}
}

void ProcessLeftRange(vector<int > number, int index, vector<int > invalidDigits, int nextSum)
{
	if (index < 0)
	{
		leftRange.push_back(nextSum);
		return;
	}

	number[index] += nextSum;
	int nextDigit = FindNextDigit(number[index], invalidDigits);
	leftRange.push_back(nextDigit);

	if (nextDigit < number[index])
	{
		ProcessLeftRange(number, index - 1, invalidDigits, 1);
	}
	else
	{
		ProcessLeftRange(number, index - 1, invalidDigits, 0);
	}
}

int GetNextLargerNumber(vector<int > number, vector<int > invalidDigits)
{
	int index = FindFirstInvalidIndex(number, invalidDigits);
	if (index == number.size())
	{
		return ConvertArrayToNumber(number);
	}

	ProcessRightRange(number, index + 1, invalidDigits);

	ProcessLeftRange(number, index, invalidDigits, 0);
	reverse(leftRange.begin(), leftRange.end());

	for (int i = index + 1; i < number.size(); i++)
	{
		leftRange.push_back(number[i]);
	}

	return ConvertArrayToNumber(leftRange);
}

int main()
{	
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/

	int n, k;
	cin >> n >> k;

	vector<int > a(k);
	for (auto &it : a)
		cin >> it;

	/*for (int i = 0; i <= 10000; i++)
	{
		vector<int > numberDigits = GetNumberInDigits(i);

		int res = GetNextLargerNumber(numberDigits, a);
		cout << res << endl;
		leftRange.clear();
	}*/

	vector<int > numberDigits = GetNumberInDigits(n);

	int res = GetNextLargerNumber(numberDigits, a);
	cout << res << endl;

	return 0;
}


Compiler output:
a.cc: In function 'std::vector<int> GetNumberInDigits(int)':
a.cc:17:9: error: 'reverse' was not declared in this scope
   17 |         reverse(res.begin(), res.end());
      |         ^~~~~~~
a.cc: In function 'int GetNextLargerNumber(std::vector<int>, std::vector<int>)':
a.cc:131:9: error: 'reverse' was not declared in this scope
  131 |         reverse(leftRange.begin(), leftRange.end());
      |         ^~~~~~~
a.cc: In function 'int FindNextMinDigit(int, std::vector<int>)':
a.cc:88:1: warning: control reaches end of non-void function [-Wreturn-type]
   88 | }
      | ^