#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long int LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI = acos(-1.0L);
__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
signed main() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  for (int i = 0; i < (int)(n); i++) ans[i] = -1;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if ((ans[s] != -1 && ans[s] != c) || (s == 0 && c == 0))
      return cout << -1 << endl, 0;
    ans[s] = c;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (ans[i] == -1)
      cout << 0;
    else
      cout << ans[i];
  }
  cout << endl;
  return 0;
}
