#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 10);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == 10 || a[s] == c) {
      a[s] = min(a[s], c);
    } else {
      cout << -1 << endl;
      ;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] == 0) {
        cout << -1 << endl;
        ;
        return 0;
      } else if (a[i] == 10) {
        cout << 1;
        ;
      } else {
        cout << a[i];
        ;
      }
    } else {
      if (a[i] == 10) {
        cout << 0;
        ;
      } else {
        cout << a[i];
        ;
      }
    }
  }
  cout << "" << endl;
  ;
}
