#include <bits/stdc++.h>
using namespace std;
long long dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const long long maxn = 1e5;
const long long OO = 1e18;
const long long mod = 1e9 + 7;
const long double PI = acos(-1);
void maxself(long long &a, long long b) { a = max(a, b); }
void minself(long long &a, long long b) { a = min(a, b); }
vector<vector<long long> > g(maxn);
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> num(n + 1, 0);
  bool f = 1;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    if (num[s] != 0 and num[s] != c) f = 0;
    num[s] = c;
  }
  if (f == 0 or (n > 1 and num[1] == 0)) {
    cout << -1;
    return 0;
  }
  for (long long i = 1; i <= n; i++) cout << num[i];
  return 0;
}
