#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
const ld PI = (acos(-1));
const ll MOD = 1000000007;
struct __io_async {
  __io_async() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};
int resolve(const int n, const vpii &sc) {
  for (ll i = ((ll)0); i < ((ll)1000); ++i) {
    str s = to_string(i);
    if (s.length() != n) continue;
    for (ll j = ((ll)0); j < ((ll)sc.size()); ++j) {
      if (s[sc[j].first - 1] != sc[j].second + '0') break;
      if (j == sc.size() - 1) return i;
    }
  }
  return -1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vpii sc(m);
  for (ll i = ((ll)0); i < ((ll)m); ++i) {
    cin >> sc[i].first >> sc[i].second;
  }
  cout << resolve(n, sc) << "\n";
  return 0;
}
