#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
long long a, b, c, d;
long long x, y, X1, Y1, X2, Y2;
bool check(long long X, long long Y) {
  if (X >= X1 && X <= X2 && Y >= Y1 && Y <= Y2) return true;
  return false;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long dis[n];
  memset(dis, -1, sizeof(dis));
  long long f = 0;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (dis[s] != -1 && dis[s] != c)
      f = 1;
    else if (s == 0 && c == 0 && n != 1)
      f = 1;
    else
      dis[s] = c;
  }
  if (f)
    cout << "-1";
  else {
    for (long long i = 0; i < n; i++) {
      if (dis[i] == -1) {
        dis[i] = 1;
      }
      cout << dis[i];
    }
  }
}
int main() {
  fast();
  int t = 1;
  while (t--) {
    solve();
  }
}
