#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > sc(m);
  for (int i = 0; i < m; i++) cin >> sc[i].first >> sc[i].second;
  if (n == 1) {
    bool flag = 1;
    for (int i = 0; i < m; i++)
      if (sc[i].second != 0) {
        flag = 0;
        break;
      }
    if (flag) {
      cout << 0;
      return 0;
    }
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    int ii = i;
    vector<int> d(3);
    for (int j = 2; j > -1; j--) {
      d[j] = ii % 10;
      ii /= 10;
    }
    bool ok = 1;
    for (int j = 0; j < m; j++)
      if (d[sc[j].first - 1] != sc[j].second) {
        ok = 0;
        break;
      }
    if (ok) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
