#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > q(m);
  for (int(i) = 0; (i) < (m); (i)++) {
    int s, c;
    cin >> s >> c;
    q[i] = make_pair(s, c);
  }
  if (n == 1) {
    for (int(i) = 0; (i) < (10); (i)++) {
      int ju = 1;
      string s = to_string(i);
      for (auto p : q)
        if (s[p.first - 1] != '0' + p.second) ju = 0;
      if (ju) {
        cout << i << endl;
        break;
      }
    }
  } else {
    for (int(i) = 0; (i) < (10000); (i)++) {
      int ju = 1;
      string s = to_string(i);
      if (s.size() > n) {
        cout << -1 << endl;
        break;
      }
      for (auto p : q)
        if (s[p.first - 1] != '0' + p.second) ju = 0;
      if (ju) {
        cout << i << endl;
        break;
      }
    }
  }
}
