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