#include <bits/stdc++.h>
using namespace std;
long long a[10];
long long n, m;
int main() {
  register int i, j;
  for (i = 1; i <= 10; i++) a[i] = -1;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    if (a[x] == -1)
      a[x] = y;
    else if (a[x] != y) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[1] == -1 || a[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 1; i <= n; i++)
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  cout << endl;
  return 0;
}
