#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> sc(M, vector<int>(2));
  for (int i = 0; i < (int)(M); i++)
    for (int j = 0; j < (int)(2); j++) cin >> sc[i][j];
  for (int i = 0; i < (int)(M); i++) sc[i][0]--;
  vector<int> ans(N);
  vector<int> c(N);
  for (int i = 0; i < (int)(M); i++) {
    if (c[sc[i][0]] == 1 && ans[sc[i][0]] != sc[i][1]) {
      cout << -1;
      return 0;
    }
    ans[sc[i][0]] = sc[i][1];
    c[sc[i][0]] = 1;
  }
  if (ans[0] == 0) {
    cout << -1;
    return 0;
  }
  int answ = 0;
  for (int i = N - 1; i >= 0; i--) {
    answ += ans[i] * pow(10, N - 1 - i);
  }
  cout << answ;
}
