#include <bits/stdc++.h>
using namespace std;
int s[10], c[10];
int ans[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int i, j;
  for (i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (i = 0; i < m; i++) {
    if (s[i] > n) {
      cout << -1 << endl;
      return 0;
    }
    for (j = 0; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i]] = c[i];
  }
  if (ans[0] == 0) ans[0] = 1;
  for (i = 1; i < n + 1; i++) {
    cout << ans[i];
  }
  cout << endl;
}
