#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string s = "";
  for (long long i = 0; i < n; i++) s.push_back('.');
  long long flag = 0;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    if (s[a] != '.' && b + '0' != s[a]) {
      flag = 1;
      break;
    }
    s[a] = b + '0';
  }
  if (flag)
    cout << -1;
  else if (n > 1 && s[0] == '0')
    cout << -1;
  else {
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '.') s[i] = '0';
      ans = ans * 10 + s[i] - '0';
    }
    cout << ans;
  }
}
