#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = 2147483647;
const long long LINF = 9223372036854775807;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int d[10], n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  memset(d, -1, sizeof(d));
  for (int(i) = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1;
      return 0;
    }
    if (d[s] != -1 && d[s] != c) {
      cout << -1;
      return 0;
    }
    d[s] = c;
  }
  for (int(i) = 0; i < (n); i++) {
    if (d[i] == -1 && i == 0)
      cout << 1;
    else if (d[i] == -1)
      cout << 0;
    else
      cout << d[i];
  }
  return 0;
}
