#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  vector<int> Num(n);
  for (int i = 0; i < n; i++) Num[i] = -1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    s[i] = x;
    c[i] = y;
  }
  for (int i = 0; i < m; i++) {
    if (Num[s[i] - 1] == -1)
      Num[s[i] - 1] = c[i];
    else {
      if (Num[s[i] - 1] != c[i]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (Num[i] == -1) Num[i] = 0;
  }
  if (Num[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << Num[i];
  }
  cout << endl;
  return 0;
}
