#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long s, c;
  long long a[n], flag = 0;
  memset(a, -1, sizeof(a));
  for (__typeof(m) i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (a[s] == -1) {
      a[s] = c;
    } else if (a[s] != c) {
      flag = 1;
    }
  }
  long long cnt = 0;
  if (a[0] == 0) flag = 1;
  for (__typeof(n) i = 0; i < n; i++) {
    if (a[i] == -1) {
      cnt++;
    } else
      break;
  }
  for (__typeof(n) i = 0; i < n; i++) {
    if (cnt > 0) {
      a[i] = 9;
      cnt--;
    } else
      break;
  }
  if (flag)
    cout << -1;
  else {
    for (long long i = 0; i < n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    solve();
  }
  cerr << endl << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  return 0;
}
