#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 && ans[s] != c)) {
      cout << -1;
      return 0;
    } else
      ans[s] = c;
  }
  int res = 0;
  for (int i = 1; i <= N; i++) {
    res *= 10;
    if (ans[i] >= 0)
      res += ans[i];
    else if (i == 1 && N > 1)
      res += 1;
  }
  cout << res;
}
