#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec s(M), c(M);
    REP(i,0,M) {
        cin >> s[i] >> c[i];
        --s[i];
    }

    ll d = 1;
    bool f = true;
    REP(i,0,N) d *= 10;
    REP(i,N==1?0:d/10,d) {
        string S = to_string(i);
        f = true;
        REP(j,0,M) {
            if(!(s[j] < SZ(S) && S[s[j]]-'0' == c[j])) {
                f = false;
                break;
            }
        }
        if(f) {
            PR(i);
            break;
        }
    }
    if(!f) PR(-1);

    return 0;
}

/*



*/
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, m;
  cin >> n >> m;
  vector<char> res(n, 0);
  for (int i = 1; i <= m; i++) {
    int s; char c;
    cin >> s >> c;
    s--;
    if (res[s] == 0) res[s] = c;
    else if (res[s] != c) {
      cout << -1 << '\n';
      return;
    }
  }
  if (n > 1) {
    if (res[0] == '0') {
      cout << -1 << '\n';
      return;
    }
    if (res[0] == 0) {
      res[0] = '1';
    }
  }
  for (auto &i : res) {
    if (i == 0) cout << '0';
    else cout << i;
  }
  cout << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}
