#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << a;
  cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
void Main() {
  int n, m;
  cin >> n >> m;
  string s = "";
  for (long long i = (long long)(0); i < (long long)(n); i++) s[i] = '*';
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    int x, y;
    cin >> x >> y;
    if (s[x - 1] != '*' && s[x - 1] - '0' != y) {
      pr(-1);
      return;
    }
    s[x - 1] = (char)(y + '0');
  }
  reverse((s).begin(), (s).end());
  if (n > 1 && s[0] == '0') {
    pr(-1);
    return;
  }
  string ans = "{";
  for (long long x = (long long)(0); x < (long long)(1000); x++) {
    stringstream ss;
    string t;
    ss << x;
    ss >> t;
    for (long long i = (long long)(0); i < (long long)(n); i++) {
      if (s[i] != '*' && s[i] != t[i]) goto next;
    }
    ans = min(ans, t);
  next:;
  }
  if (ans == "{") ans = "-1";
  pr(ans);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
