#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int ans[N];
  for (int j = 0; j < N; j++) {
    ans[j] = 0;
  }
  for (int x = 0; x < M; x++) {
    for (int y = x + 1; y < M; y++) {
      if (s[x] == s[y] && c[x] != c[y]) {
        cout << -1 << endl;
        return 0;
      }
    }
    ans[s[x] - 1] = c[x];
  }
  if (N > 1 && ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int k = 0; k < N; k++) {
    cout << ans[k];
  }
  cout << endl;
  return 0;
}
