#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e10;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  bool found = false;
  long long int a[m][2];
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> a[i][0] >> a[i][1];
  }
  long long int ans;
  for (long long int i = pow(10, n - 1); i < pow(10, n) && !found; i++) {
    long long int temp = 0;
    for (long long int j = 0; j < m; j++) {
      long long int no = i / pow(10, n - a[j][0]);
      no %= 10;
      if (no == a[j][1]) temp++;
    }
    if (temp == m) ans = i, found = true;
  }
  if (found) {
    cout << ans;
  } else
    cout << -1;
  return 0;
}
