#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double EPS = 0.0000000001;
int n, m;
bool check(int x, vector<int> v) {
  string s = to_string(x);
  for (int i = 0; i < s.size(); i++) {
    if (v[i + 1] == -1) continue;
    if ((s[i] - '0') != v[i + 1]) return false;
  }
  return true;
}
int main() {
  cin >> n >> m;
  vector<int> s(m), c(m);
  vector<int> v(n + 1);
  for (long long i = 0; i < n + 1; i++) v[i] = -1;
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (v[s[i]] != -1 and v[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    v[s[i]] = c[i];
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    if (check(i, v)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
