#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  if (n == 1) {
    int a = -1;
    while (m--) {
      int s, c;
      cin >> s >> c;
      if (s == 1 && c == 0) {
        cout << -1;
        return 0;
      }
      if (s == 1 && a == -1) {
        a = c;
      } else if (s == 1 && c != a) {
        cout << -1;
        return 0;
      } else {
        continue;
      }
    }
    cout << a;
    return 0;
  }
  while (m--) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] == -1 || v[s] == c) {
      v[s] = c;
      continue;
    }
    if (v[s] != c) {
      cout << -1;
      return 0;
    }
  }
  if (v[0] == 0) {
    cout << -1;
  } else {
    int ans = 0;
    if (v[0] == -1) v[0] = 1;
    for (int i = 0; i < n; ++i) {
      if (v[i] == -1) v[i]++;
      ans = ans * 10 + v[i];
    }
    cout << ans;
  }
  return 0;
}
