#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int n, m, ans = 1e9;
vector<P> sc(5);
int main() {
  cin >> n >> m;
  for (ll i = 0; i < ll(m); i++) cin >> sc[i].first >> sc[i].second;
  for (ll i = 100; i < ll(1000); i++) {
    int cnt = 0;
    string str = to_string(i);
    for (ll i = 0; i < ll(m); i++) {
      int f = sc[i].first, s = sc[i].second;
      f--;
      if (str[f] - '0' == s) cnt++;
    }
    if (cnt == m) chmin(ans, (int)i);
  }
  if (ans == 1e9)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return 0;
}
