#include <iostream>
#include <string>
#include <sstream>
int main()
{
std::ios_base::sync_with_stdio( false );
unsigned long long bookCount;
std::string input1;
std::string input2;
std::cin >> bookCount;
std::cin.get();
std::getline( std::cin, input1 );
std::getline( std::cin, input2 );
unsigned long long* sequence1 = new unsigned long long[ bookCount ];
unsigned long long* sequence2 = new unsigned long long[ bookCount ];
unsigned long long* sequence3 = new unsigned long long[ bookCount ];
unsigned long long index = 0;
unsigned long long cursor = 0;
for ( unsigned long long i = 0; i < input1.length(); ++i )
{
if ( input1[ i ] == ' ' )
{
std::stringstream stream( input1.substr( cursor, i - cursor ) );
stream >> sequence1[ index ];
index++;
cursor = i + 1;
}
}
std::stringstream stream( input1.substr( cursor, input1.npos ) );
stream >> sequence1[ index ];
index = 0;
cursor = 0;
for ( unsigned long long i = 0; i < input2.length(); ++i )
{
if ( input2[ i ] == ' ' )
{
std::stringstream stream( input2.substr( cursor, i - cursor ) );
stream >> sequence2[ index ];
index++;
cursor = i + 1;
}
}
stream = std::stringstream( input2.substr( cursor, input2.npos ) );
stream >> sequence2[ index ];
sequence2[ index ] = atol( input2.substr( cursor, input2.npos ).c_str() );
unsigned long long lowestUnread = 1;
bool* booksRead = new bool[ bookCount ];
for ( unsigned long long i = 0; i < bookCount; ++i )
{
booksRead[ i ] = false;
}
for ( unsigned long long i = 0; i < bookCount; ++i )
{
if ( lowestUnread != sequence1[ i ] && lowestUnread != sequence2[ i ] )
{
sequence3[ i ] = lowestUnread;
booksRead[ lowestUnread - 1 ] = true;
while ( lowestUnread < bookCount && booksRead[ lowestUnread - 1 ] )
{
lowestUnread++;
}
}
else
{
unsigned long long j = lowestUnread + 1;
bool mustFlip = true;
while ( j <= bookCount )
{
if ( j != sequence1[ i ] && j != sequence2[ i ] && !booksRead[ j - 1 ] )
{
sequence3[ i ] = j;
booksRead[ j - 1 ] = true;
if ( j == lowestUnread )
{
while ( booksRead[ lowestUnread - 1 ] )
{
lowestUnread++;
}
}
mustFlip = false;
break;
}
j++;
}
if ( mustFlip )
{
for ( unsigned long long k = 0; k < bookCount; ++k )
{
if ( lowestUnread != sequence1[ k ] && lowestUnread != sequence2[ k ] &&
sequence3[ k ] != sequence1[ i ] && sequence3[ k ] != sequence2[ i ] )
{
sequence3[ i ] = sequence3[ k ];
sequence3[ k ] = lowestUnread;
booksRead[ lowestUnread - 1 ] = true;
break;
}
}
}
}
}
for ( unsigned long long i = 0; i < bookCount; ++i )
{
if ( sequence3[ i ] == sequence1[ i ] || sequence3[ i ] == sequence2[ i ] )
{
for ( unsigned long long j = 0; j < bookCount; ++j )
{
if ( j != i && sequence3[ i ] != sequence1[ j ] && sequence3[ i ] != sequence2[ j ] &&
sequence3[ j ] != sequence1[ i ] && sequence3[ j ] != sequence2[ i ] )
{
unsigned long long temp = sequence3[ i ];
sequence3[ i ] = sequence3[ j ];
sequence3[ j ] = temp;
break;
}
}
}
}
for ( unsigned long long i = 0; i < bookCount; ++i )
{
std::cout << sequence3[ i ] << " ";
}
delete[] sequence1;
delete[] sequence2;
delete[] sequence3;
delete[] booksRead;
return 0;
}