#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int ans;
  vector<int> num(N, -1);
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  bool ok = true;
  for (int i = 0; i < M; i++) {
    if (num[s[i]] == -1 || num[s[i]] == c[i])
      num[s[i]] = c[i];
    else
      ok = false;
  }
  if (M > N)
    ans = -1;
  else if (num[0] == 0)
    ans = -1;
  else if (!ok)
    ans = -1;
  else {
    ans = 0;
    for (int i = 0; i < N; i++) {
      if (num[i] == -1) continue;
      ans += num[i] * (int)pow(10, N - i - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
