#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int(i) = 0; (i) < (M); (i)++) cin >> s[i] >> c[i];
  int keta = 0;
  int ans = 999999;
  for (int(now) = 0; (now) < (1000); (now)++) {
    keta = 0;
    int tmp = now;
    bool flg = true;
    while (tmp > 0) {
      tmp /= 10;
      keta++;
    }
    if (now = 0) keta = 1;
    if (keta != N) continue;
    int cnt[keta];
    tmp = now;
    for (int(i) = 0; (i) < (3); (i)++) {
      cnt[i] = tmp % 10;
      tmp /= 10;
    }
    for (int(i) = 0; (i) < (M); (i)++) {
      if (cnt[N - s[i]] != c[i]) {
        flg = false;
        continue;
      }
    }
    if (flg) ans = min(now, ans);
  }
  if (ans == 999999)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
