#include <bits/stdc++.h>
using namespace std;
const int mod = 100000007;
const int inf = 100000005;
const int N = 200005, M = N;
int i, j, n, m;
long long cnt, idx;
vector<int> temp;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<int> vec(n, -1);
  long long x, y;
  int f = 0;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (vec[x - 1] != -1 && vec[x - 1] != y) f = 1;
    vec[x - 1] = y;
  }
  if (f || (vec[0] == 0 && n != 1)) {
    cout << "-1\n";
    return;
  }
  for (i = 0; i < n; i++) {
    if (vec[i] == -1)
      cout << "0";
    else
      cout << vec[i];
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
