#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, set<int>> mm;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    mm[a].insert(b);
  }
  for (auto i = mm.begin(); i != mm.end(); i++) {
    set<int> v = i->second;
    if (v.size() > 1 || (*v.begin() == 0 && i->first == 1))
      return cout << -1, 0;
  }
  int arr[n + 1];
  memset(arr, 0, sizeof arr);
  for (auto i = mm.begin(); i != mm.end(); i++) {
    set<int> v = i->second;
    arr[i->first] = *v.begin();
  }
  for (int i = 1; i <= n; i++) cout << arr[i];
  cout << '\n';
  return 0;
}
