#include <bits/stdc++.h>
using namespace std;
int N, M, ans[10], fg = 1;
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) ans[i] = -1;
  for (int i = 1; i <= M; i++) {
    int s, c;
    cin >> s >> c;
    if ((ans[s] != -1 && c != ans[s]))
      fg = 0;
    else
      ans[s] = c;
  }
  if (!fg)
    cout << -1 << endl;
  else {
    int res = 0;
    for (int i = 1; i <= N; i++) {
      if (ans[i] != -1)
        res = res * 10;
      else
        res = res * 10 + ans[i];
    }
    if (res <= 0) res = -1;
    cout << res;
  }
}
