#include <bits/stdc++.h>
using namespace std;
int DivUp(long long a, long long b) { return (a + (b - 1) / b); }
int main() {
  int n, m;
  bool isIncludeOne = false;
  cin >> n >> m;
  vector<int> s(m), c(m), ans(n);
  vector<bool> check(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) ans[i] = 9;
  if (n == 1) {
    for (int i = 0; i < n; i++) {
      if (c[i] == 0 && s[i] == 1) {
        cout << c[i] << endl;
        return 0;
      }
    }
  }
  if (n > 1) {
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && c[i] != 0) {
        ans[i] = min(ans[i], c[i]);
        isIncludeOne = true;
        check[0] = true;
      }
      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (!isIncludeOne) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = min(ans[s[i] - 1], c[i]);
    check[s[i] - 1] = true;
  }
  for (int i = 0; i < n; i++)
    if (!check[i]) ans[i] = 0;
  for (int i = 0; i < n; i++) cout << ans[i];
  cout << endl;
  return 0;
}
