#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  bool f = true;
  for (int i = 0; i < m; ++i) {
    if (a[s[i] - 1] != 0 && a[s[i] - 1] != c[i]) {
      f = false;
      break;
    }
    a[s[i] - 1] = c[i];
  }
  int num;
  for (auto x : s) {
    if ((num = count(s.begin(), s.end(), x)) > 1) {
      vector<int> v(num);
      for (int i = 0; i < num; ++i) {
        auto it = find(s.begin() + i, s.end(), x);
        v[i] = it - s.begin();
      }
      for (int i = 1; i < num; ++i) {
        if (c[v[i - 1]] != c[v[i]]) {
          f = false;
          break;
        }
      }
    }
    if (!f) break;
  }
  if (a[0] == 0) {
    if (find(s.begin(), s.end(), 1) == s.end())
      a[0] = 1;
    else if (n > 1)
      f = false;
  }
  if (f) {
    for (auto x : a) cout << x;
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
