#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M), ans(N, 0), ch(N, 0);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (ch[s[i] - 1] == 0) {
      ans[s[i] - 1] = c[i];
      ch[s[i] - 1] = 1;
    } else {
      if (ans[s[i] - 1] != c[i]) {
        cout << "-1";
        break;
      }
    }
    if (i == N - 1) {
      if (ans[0] == 0) {
        cout << "-1";
      } else {
        for (int i = 0; i < N; i++) {
          cout << ans[i];
        }
      }
    }
  }
}
