#include <bits/stdc++.h>
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; ++i) a[i] = -1;
  int s[m], c[m];
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < m; ++i) {
    --s[i];
    if (a[s[i]] != -1 and a[s[i]] != c[i]) {
      cout << -1 << '\n';
      return 0;
    }
    a[s[i]] = c[i];
  }
  int ans = 0;
  int ten = 1;
  for (int i = m - 1; i >= 0; --i) {
    if (a[i] != -1) {
      ans += ten * a[i];
    } else {
      int num = 0;
      if (i == 0) num = 1;
      ans += ten * num;
    }
    ten *= 10;
  }
  int sn = to_string(ans).size();
  if (n != sn) {
    ans = -1;
  }
  cout << ans << '\n';
  return 0;
}
