#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) {
      cout << 0;
      return 0;
    } else {
      cout << -1;
      return 0;
    }
  }
  vector<int> s(m);
  vector<int> c(m);
  vector<int> a(n, 0);
  vector<bool> flag(n, true);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (flag[s[i]]) {
      a[s[i]] = c[i];
      flag[s[i]] = false;
    } else if (a[s[i]] == c[i]) {
    } else {
      cout << -1;
      return 0;
    }
  }
  if (n >= 2 && a[0] == 0 && !flag[0]) {
    cout << -1;
    return 0;
  }
  int ans = 0;
  int x = 1;
  for (int i = n - 1; i >= 0; i--) {
    ans += a[i] * x;
    x *= 10;
  }
  cout << ans;
  return 0;
}
