#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (106)

int n, m, C[MAXN], ok[MAXN*MAXN];
pi E[MAXN*MAXN];
bitset<MAXN> vis;
vector<pi> v[MAXN];

int main() {
	FAST
	cin>>n>>m;
	FOR(i,1,m){
		cin>>E[i].f>>E[i].s;
	}
	FOR(i,1,n) cin>>C[i];
	FOR(i,1,m) {
		int a=E[i].f, b=E[i].s;
		if(C[a] > C[b]) {
			v[a].eb(b, 0), ok[i]=a;
		} else if(C[a] < C[b]) {
			v[b].eb(a, 0), ok[i]=b;
		} else {
			v[a].eb(b, i), v[b].eb(a, i);
		}
	}
	
	function<void(ll)>dfs=[&](ll x){
		if(vis[x]) return;
		vis[x]=1;
		for(auto i:v[x]) {
			if(i.s) {
				ok[i.s] = x;
			}
			dfs(i.f);
		}
	};
	FOR(i,1,n) dfs(i);
	FOR(i,1,m) {
		assert(ok[i]==E[i].f||ok[i]==E[i].s);
		if(ok[i] == E[i].f) cout<<"->\n";
		else cout<<"<-\n";
	}
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  multiset<int> have;
  set<int> st;
  for (int i = 0; i <= n; i++) st.emplace(i);
  int ans = 1 << 30;
  for (int i = 0; i < n; i++) {
    have.emplace(a[i]);
    if (st.count(a[i])) st.erase(a[i]);
    if (i - m >= 0) {
      have.erase(have.find(a[i - m]));
      if (have.find(a[i - m]) == have.end()) st.emplace(a[i - m]);
    }
    if (i >= m - 1) {
      if (!st.empty()) ans = min(ans, *st.begin());
    }
  }
  cout << ans << endl;
}
