#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> v(n, -1);
  for (int i = 0; i < (m); ++i) {
    if (v[s[i]] == -1) {
      v[s[i]] = c[i];
    } else {
      if (v[s[i]] != c[i]) {
        cout << -1 << endl;
        return;
      }
    }
  }
  if (v[0] == 0) {
    cout << -1 << endl;
    return;
  }
  if (v[0] == -1) v[0] = 1;
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    ans += max(v[i], 0) * pow(10, n - i - 1);
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
