#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const long long INFTY = (1LL << 32);
const double PI = 3.1415926535;
const int MOD = 1000000007;
template <typename T = long long>
T in() {
  T x;
  cin >> x;
  return (x);
}
signed main(void) {
  long long n, m;
  cin >> n >> m;
  long long num[n];
  for (long long i = 0; i < n; i++) num[i] = -1;
  bool flag = true;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    if (num[s - 1] != -1 and num[s - 1] != c)
      flag = false;
    else
      num[s - 1] = c;
  }
  if (flag) {
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      if (num[i] == -1) num[i] = 0;
      ans = ans * 10 + num[i];
    }
    if (ans == 0)
      cout << -1 << endl;
    else
      cout << ans << endl;
  } else
    cout << -1 << endl;
}
