#include <bits/stdc++.h>
using namespace std;
int N, M;
int s[5];
int c[5];
void input() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
}
void solve() {
  int ans = 0;
  for (int i = 0; i < N; i++) {
    bool flag = false;
    int num = 0;
    for (int j = 0; j < M; j++) {
      if (i + 1 == s[j]) {
        if (i == 0 && c[j] == 0) {
          ans = -1;
          break;
        }
        if (flag) {
          if (num != c[j]) {
            ans = -1;
            break;
          }
        }
        num = c[j];
        flag = true;
      }
    }
    if (ans == -1) break;
    ans += num * pow(10, (N - i - 1));
  }
  if (ans < 10) ans = -1;
  cout << ans << endl;
}
int main() {
  input();
  solve();
  return 0;
}
