#include <bits/stdc++.h>
using namespace std;
int a[1000];
int s[1000], c[1000];
signed main() {
  int n, m;
  cin >> n >> m;
  int mx = 0;
  for (register int i = 1; i <= m; ++i) {
    cin >> s[i] >> c[i];
    if (((a[s[i]]) && (a[s[i]] != c[i])) || c[i] == 0) {
      puts("-1");
      return 0;
    } else {
      a[s[i]] = c[i];
      mx = max(mx, s[i]);
    }
  }
  for (register int i = 1; i <= mx; ++i) cout << a[i];
  return 0;
}
