#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>

using namespace std;

int a, b;
int aBoard[1010];
int bBoard[1010];

int main(void)
{
	scanf("%d%d", &a, &b);
	
	if (a >= b) {
		for (int i = 0 ; i < a ; i++) {
			aBoard[i] = i + 1;
		}
		int left = a;
		for (int i = 0 ; i < b ; i++) {
			bBoard[i] = left;
			left--;
		}
		
		while (left > 0) {
			for (int i = 0 ; i < b ; i++) {
				bBoard[i] = bBoard[i] + left;
				left--;
				if (left <= 0)
					break;
			}
		}
	} else {
		for (int i = 0 ; i < b ; i++) {
			bBoard[i] = i + 1;
		}
		int left = b;
		for (int i = 0 ; i < a ; i++) {
			aBoard[i] = left;
			left--;
		}
		
		while (left > 0) {
			for (int i = 0 ; i < a ; i++) {
				aBoard[i] = aBoard[i] + left;
				left--;
				if (left <= 0)
					break;
			}
		}
	}
	
	for (int i = 0 ; i < a ; i++) {
		printf("%d ", aBoard[i]);
	}
	for (int i = 0 ; i < b ; i++) {
		printf("%d ", -bBoard[i]);
	}	
	
	printf("\n");
	
	return 0;
}
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define bit(x,j) ((x>>j)&1)
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
ll int mod=998244353;
int mul(ll int x, ll int y)
{
    return (x * 1ll * y) % mod;
}

ll int add(ll int x,ll int y)
{
    x += y;
    while(x >= mod) x -= mod;
    while(x < 0) x += mod;
    return x;
}

long long power(long long a, long long b,ll m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res%m;
    }


  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j]+C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
  bool prime[10000000];
void Sieve(ll int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 


//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
int sum(int n)  
{  
    if (n == 0)  
    return 0;  
    return (n % 10 + sum(n / 10));  
}  
ll int factori(ll int n,ll int m) 
{ 
    ll int fact = 1; 
    for(int i=2;i<=n;i++) { 
        fact = (fact * i)%m; 
    } 
    return fact%m; 
} 

int reduce(int x, int y) 
{ 
    int d; 
    d = __gcd(x, y); 
  
    x = x / d; 
    y = y / d; 
    return x; 
} 

int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
  
        if (arr[mid] == x) 
            return mid; 
  
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
  
        // Else the element can only be present 
        // in right subarray 
        return binarySearch(arr, mid + 1, r, x); 
    } 
  
    // We reach here when element is not 
    // present in array 
    return -1; 
} 

long long gcd(long long int a, long long int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
 
// Function to return LCM of two numbers 
long long lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}

ll int money_left(ll int money_left,long long int a[],ll int n)
{
    ll int l = 0, r = n;
    while (l < r)
    {
        ll int m = (l + r + 1) / 2;
        if (a[m] <= money_left) l = m; else r = m-1;
    }
    return l;
}
ll int dp[1005][1005];
ll int n,m;
ll int a[1005],b[1005];
ll int fun(int i,int j)
{
    if(i==n || j==m)
    return max(n-i,m-j);
    if(dp[i][j]!=-1)
    return dp[i][j];
    dp[i][j]=1e18;
    if(a[i]==b[j])
    {
        dp[i][j]=min(dp[i][j],fun(i+1,j+1));
    }
    dp[i][j]=min(dp[i][j],1+fun(i+1,j));
    dp[i][j]=min(dp[i][j],1+fun(i,j+1));
    dp[i][j]=min(dp[i][j],1+fun(i+1,j+1));
    return dp[i][j];
}

 int main() {
    ios;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    memset(dp,-1,sizeof(dp));
    cout<<fun(0,0)<<endl;
}
