#include <bits/stdc++.h>
using namespace std;
long long inf = 100000000;
long long s[25], c[25], ans[25];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 25; i++) {
    ans[i] = 0;
  }
  pair<long long, long long> p[25];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (n != 1 && s[i] == 1 && c[i] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (s[i] == n && c[i] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    p[i] = make_pair(s[i], c[i]);
  }
  sort(p, p + m);
  for (int i = 1; i < m; i++) {
    if (p[i].first == p[i - 1].first) {
      if (p[i].second != p[i - 1].second) {
        cout << "-1" << endl;
        return 0;
      } else {
        if (i == 1) {
          ans[p[i - 1].first] = p[i - 1].second;
        }
        if (ans[p[i].first] == 0) {
          ans[p[i].first] = p[i].second;
        }
      }
    }
    if (ans[p[i].first] == 0) {
      ans[p[i].first] = p[i].second;
    }
  }
  if (ans[1] == 0) {
    ans[1] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
