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